I recently found some samples of code with Asp.Net Mvc2 that makes some ajax calls to actions in controller that returns ContentResult.
I experienced some problems while trying to convert these samples in Mvc3 without changing the return type of actions to JsonResult.
Can anyone explain to me what is the difference between ContentResult and JsonResult in the context of ajax calls and in which cases can I use one or the other in the context of ajax calls? I found a good post here that explains in detail each type of result but it's not enough to answer my question.
Is there a known issues with ContentResult and ajax calls in Mvc3?
Thank you.
If the result your JavaScript code gets back is a piece of content such as HTML, you should return a ContentResult or a PartialViewResult (if the HTML is formatted using a partial view).
If the result is an object (especially one you then want to manipulate), then it should be a JsonResult.
Here are some good examples of working with JSON: http://geekswithblogs.net/michelotti/archive/2008/06/28/mvc-json---jsonresult-and-jquery.aspx
Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With