I am using $.ajax
method to get the data from the MVC controller. I am usingPOST
method according to the JSON Hijacking for security standards. If I debug I am able to get the data in controller, but after returning data to the $.ajax's success function then it is showing me empty json array like below.
enter image description here
In controller I am using method as below:
public async Task<ActionResult> GetUsersFromOrganization(string searchString) {
string accessToken = await SampleAuthProvider.Instance.GetUserAccessTokenAsync();
var result = await graphService.GetUsersFromOrg(accessToken, searchString);
var json = JObject.Parse(result);
var valueJSON = json.GetValue("value");
return Json(valueJSON, JsonRequestBehavior.AllowGet);
}
json
contains below data:
enter image description here
Here is the valueJSON
value
enter image description here
1 Answer 1
The valueJSON is a JToken
, Json(valueJSON)
method is serializing your valueJson as a JToken
class and not as the deserialized array of objects that you need, you can try to return the JToken
as a string with return Content(valueJSON .ToString(),"application/json");
or parse the JToken
to the original array of objects.
1 Comment
valueJSON.ToString()
then in success method of ajax it is giving me values. Thank you
valueJSON
?