0

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

asked Mar 5, 2018 at 16:18
10
  • In your C# code, what is valueJSON? Commented Mar 5, 2018 at 16:19
  • Change your code like this. It may be helpful stackoverflow.com/a/46532175/2946329 Commented Mar 5, 2018 at 16:19
  • @MarkC. it is having JSON response Commented Mar 5, 2018 at 16:23
  • That doesn't help. Commented Mar 5, 2018 at 16:23
  • @S.Akbari.. even if I tried that, same issue Commented Mar 5, 2018 at 16:24

1 Answer 1

2

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.

answered Mar 5, 2018 at 17:06

1 Comment

You are right! If I modify code as you said valueJSON.ToString() then in success method of ajax it is giving me values. Thank you

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.