0

I have an ajax call in my jquery to my MVC controller:

$.getJSON('/mysite/controller/dosomething', { postId: id }, function (data) {

The 'data' that I am returning is in the form of a JsonResult, and consists of a simple custom object with 1 property called 'Message' and another property called 'Count'. Both of these values are assigned and I am returning them as follows (edited for brevity):

[HttpGet]
public JsonResult DoSomething(int postId)
{
    var response = new MyAjaxResponseModel {Message = "Hello world!", Count = 66};
    return Json(response, JsonRequestBehavior.AllowGet);
}

In my jQuery, I then want to be able to look at both values in the Json response, but I don't know the proper way to get at these values?

1 Answer 1

1

data.Message, data.Count in the callback you're passing to $.getJSON()? To inspect the structure of your data object, you can use console.log(data) (also, in that callback)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.