Search code examples
ajaxasp.net-coreform-data

how to display the data returned by the controller action


I am trying to display the data returned by the controller action: my action:

public ActionResult RetreiveId()
{
    //....
    return Content(JsonConvert.SerializeObject(new { StatusCode = "1", JobId = NewJobId }));
}

My JSP incldes this form

<form id="write-cart-form" role="form" style="" asp-controller="Home" asp-action="RetreiveId" data-ajax="true" data-ajax-method="post" 
data-ajax-success="alert('The ID is: ' + JobId); ">

Expected Results: A pup up saying : the ID is 1234

Actual Results The ID is undefined

here is the response of that request in the etwork tab enter image description here


Solution

  • I was able to solve my problem by specfying the contenttype in the return of the action method for instance return Content(JsonConvert.SerializeObject(new { StatusCode = "1", JobId = NewJobId }), "application/json");