字符串未传递到控制器
我试图通过 $.ajax 调用发布名为“selected”的字符串,但控制器(selected=null)收到空值?根据fiddler,selected 有一个值({'selected':0100})?
[HttpPost]
public ActionResult Index(string selected)
{
return Json(new {value = "this is a test"});
}
$(document).ready(
$("#btnSave").click(
function () {
var checkboxesselected = "0100";
$.ajax({ type: 'POST',
url: "/Home/Index",
datatype: 'json',
data: "{'selected':" + checkboxesselected + "}"
});
}
)
i am trying to post my string called 'selected' trough my $.ajax call but the controller(selected=null) receives a null value? selected has a value ({'selected':0100}) according to fiddler?
[HttpPost]
public ActionResult Index(string selected)
{
return Json(new {value = "this is a test"});
}
$(document).ready(
$("#btnSave").click(
function () {
var checkboxesselected = "0100";
$.ajax({ type: 'POST',
url: "/Home/Index",
datatype: 'json',
data: "{'selected':" + checkboxesselected + "}"
});
}
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题是您将数据作为字符串文字而不是对象发送到 jQuery。包含数据参数的行应为
data: {selected: checkboxesselected }
The problem is you're sending the data to jQuery as a string literal as opposed to an object. Your line with the data parameters should be
data: {selected: checkboxesselected }
您缺少“checkboxesselected”周围的引号
You're missing the quotes around "checkboxesselected "
尝试:
然后:
……
try:
and then:
...
...