开发者

Differences using JSON with MVC & MVC2?

I recently started working with MVC or MVC2 to be more exact. I found a tutorial yesterday that was using JSON to populate a dropdowlist. Im not sure why this did not work with a MVC2 project and only with a MVC. Anybody got the time to just peep this site and maybe see what it might b开发者_开发技巧e? http://www.dotnetcurry.com/ShowArticle.aspx?ID=466. It's that JSON example, its homecontroler and the view code only

I really want to know why

thanks


There has been a change to JsonResult in MVC 2 and therefore it will no longer work with HTTP GET to avoid JSON hijacking.

So you could either change your code to return via HTTP POST or allow GET behaviour which may leave you open to JSON hijacking.

Try modifying your code to follow the to the format if you wish to use GET

[AcceptVerbs(HttpVerbs.Get)]
public JsonResult GetListViaJson()
{
  return Json(GenerateNumbers(), JsonRequestBehavior.AllowGet);
}

Or use the recommended POST

[AcceptVerbs(HttpVerbs.Post)]
public JsonResult GetListViaJson()
{
  return Json(GenerateNumbers());
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜