The ASP.NET MVC framework allows you to easily return Json from an action method. This makes jQuery Ajax calls very easy to implement, as shown below.
The JavaScript
$(.button).getJSON('/Home/GetJsonData',
{ id = 34 },
function(data) {
// Do something with it
}
);
The Action Method
public ActionResult GetJsonData(int id)
{
Person person = this.personService.GetPerson(id);
return Json(person);
}
There is only one problem with the above action method. If you attempt to run it, the call to the ActionMethod will result in a Internal Server Error (Error 500). The reason is that by default data can only be retrieved using a POST operation if your action method returns a Json result. To make this work with a GET request, all you need to use is the overloaded Json() method shown below.
public ActionResult GetJsonData(int id)
{
Person person = this.personService.GetPerson(id);
return Json(person, JsonRequestBehavior.AllowGet);
}

October 23, 2011 at 4:57 pm
It Saves a my time,
Thanks
Behtash
November 23, 2011 at 9:02 am
You rock you saved me so much headache
January 1, 2012 at 3:04 am
Thanks i saw this after putting big effort to solve this. Any way this helped me a lot. Thanks.
January 10, 2012 at 4:59 am
Great post. Resolved my issue. Thanks a lot sir.
March 19, 2012 at 12:52 pm
thanks you are awesome
May 13, 2012 at 9:25 pm
Awesome! Solved my issue
October 30, 2012 at 4:26 am
Thank you, really helpful tip!
December 5, 2012 at 12:20 pm
Awesome! Thanks a ton!