开发者

getJSON sending null parameter to controller

Guys, Im calling a JsonResult but the "getJSON" is sending a null parameter to controller.

In JS I have this...

var ID = $("#Id").val();
$.g开发者_如何学CetJSON("/Orders/JSON", ID, function (data) {
    ....    
};

The var ID has a valid value. I don't know where I'm going wrong.

public JsonResult JSONEnvolvidosPedido(string ped)
    {
         ...
    }

What am I missing?

Tks.


If you are sending data to a server, it needs to be in key=value form. You're just sending a value.

You should probably do something like this:

$.getJSON("/Orders/JSON", {id: ID}, function (data) {
    ....    
};

The exact name of the key (id here) depends on your server-side code's requirements.


be sure to add JsonRequestBehavoir.AllowGet

return Json(data, JsonRequestBehavior.AllowGet);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜