2

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

In JS I have this...

var ID = $("#Id").val();
$.getJSON("/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.

2 Answers 2

7

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.

Sign up to request clarification or add additional context in comments.

Comments

0

be sure to add JsonRequestBehavoir.AllowGet

return Json(data, JsonRequestBehavior.AllowGet);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.