in my javascript I try to call a controller method of the ASP.NET MVC V3 framework, actually I tried these both solutions:
$.get('/Controller/Method', tourID, function (data) {
$.each(data, function (index, listelement) {
...do something with listelement
});
}, "json");
$.getJSON('/Controller/Method', null, function (data) {
$.each(data, function (index, listelement) {
...do something with listelement
});
});
My Controller method looks like this:
public JsonResult GetList(int id)
{
Object obj = repository.GetObject(id);
// obj.Stuff is an EntityCollection
return Json(obj.Stuff, JsonRequestBehavior.AllowGet);
}
My problem is, the controller function is not going to be called (I have a breakpoint set here). Well if I remove the parameter “id”, it can be called, but the “$.each…” section is not going to be executed. How can I debug the interaction between javascript and ASP.NET, what is going wrong here?
Thanks in advance and best regards,
Artjom
I used the Firebug plugin to find the problem. The list I tried to return in the controller method could not be serialized due to circular dependencies. I solved this by adding the [ScriptIgnore] attribute to navigation properties of the corresponding entity class.