Json, jQuery and ASP.NET MVC
I’m stacking a few things here related to Json, jQuery and ASP.NET MVC so that I can get to them later on.
JQuery to grab some Json when a web page is loaded:
$(document).ready(function() { $.getJSON("/MyController/MyJsonAction", null, function(data) {
//do stuff with data here
}); });
The smallish code in the ASP.NET MVC controller:
public JsonResult GetJson()
{
return Json(GetList());
}
It’s possible to use anonymous types with Json() as well, which is very useful but may be harder to unit test.