开发者

How to pass data to JsonResult in ASP.NET MVC?

this must be a newbie question.

I have this method in a controller:

public JsonResult GetUpdates(string lastChatMessage)
{
   var json = Json(new {lastModeratorAction = -1});
   return json;
}

I am calling it with $.ajax or $.getJSON from Javascript. The method gets called but there is an exception somewhere. If I use $.ajax I define an "error" callback and it tells me that the status of the XmlHttpRequest is "error". The error message is "undefined".

If I return "null" from the above method it work开发者_如何学Cs fine. Probably there is an exception during JSON serialization. Any hints?


If you are using a GET to send the request, you need to indicate that it's acceptable to return a JsonResult.

 return Json( new { lastModeratorAction = -1 }, JsonRequestBehavior.AllowGet );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜