开发者

getJSON sending null parameter to controller

开发者 https://www.devze.com 2023-03-07 15:49 出处:网络
Guys, Im calling a JsonResult but the \"getJSON\" is sending a null parameter to controller. In JS I have this...

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

精彩评论

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