开发者

mvc2 migration issue

开发者 https://www.devze.com 2022-12-22 20:06 出处:网络
i migrate my mvc1 project to mvc2. my jquery json result function does not work anymore. have any idea ?

i migrate my mvc1 project to mvc2.

my jquery json result function does not work anymore. have any idea ?

aspx

$.getJSON('Customer/GetWarningList/0', function(jsonResult) {
                    $.each(jsonResult, function(i, val) {
                        $('#LastUpdates').prepend(jsonResult[i].Url);
                    });

                });

controller

public JsonResult GetWarningLi开发者_如何学编程st(string id)
        {
            List<WarningList> OldBck = new List<WarningList>();

            return this.Json(OldBck);

        }


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 have two options

a. return your results via HTTP Post 

or 

b. the JsonRequestBehavior property to JsonRequestBehavior.AllowGet

There is an interesting article on how to modify here.

or (more elegant)

c. return Json(data, JsonRequestBehavior.AllowGet);
0

精彩评论

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

关注公众号