在asp.net mvc中从ajax到actionresult的数组的空ID
我的 Ajax 函数:
function changeMultipleItemStatus(status) {
var ids= getAllCheckedIds();
var comment = $('#txtComment').val();
$.ajax({
type: 'POST',
url: "../Admin/ChangeMultipleItemStatus",
cache: false,
data: {
ids: ids,
status: status,
comment: comment
},
traditional: true,
success: function (html) {
...
}
}); }
ActionResult
[HttpPost]
public ActionResult ChangeMultipleItemStatus(int[] ids, string status, string comment)
{
....
}
function getAllCheckedIds() {
var data = [];
$("table input:checked").each(function () {
data.push($(this).val());
});
return data;
}
我的问题是 ActionResult Changemultiplestatus 第一个变量 ids 始终为 null。 当我提醒 dataToSend 时,它提醒它似乎没问题 (true,1,2) -> 1,2 是项目的 id。 但在控制器中,动作 id 始终为空。
有什么意见吗?
My Ajax function:
function changeMultipleItemStatus(status) {
var ids= getAllCheckedIds();
var comment = $('#txtComment').val();
$.ajax({
type: 'POST',
url: "../Admin/ChangeMultipleItemStatus",
cache: false,
data: {
ids: ids,
status: status,
comment: comment
},
traditional: true,
success: function (html) {
...
}
}); }
ActionResult
[HttpPost]
public ActionResult ChangeMultipleItemStatus(int[] ids, string status, string comment)
{
....
}
function getAllCheckedIds() {
var data = [];
$("table input:checked").each(function () {
data.push($(this).val());
});
return data;
}
My problem is ActionResult Changemultiplestatus first variable ids is always null.
when i alert dataToSend it alert it seems okey (true,1,2) -> 1,2 is id of items.
But in controller action ids is always null.
any comments?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在 webservice.xml 中将
int[]
id 更改为字符串 id 吗?还为空吗?还可以尝试[ [System.Web.Services.WebMethod]]
而不是[HttpPost]
Can you change
int[]
ids to string ids at webservice. Is it still null? Also try[ [System.Web.Services.WebMethod]]
instead of[HttpPost]
我绝对不会将整数更改为字符串。 Phil Haack 有一篇关于模型绑定到列表的精彩文章 - 尝试执行此操作时涉及一些技巧,因此我建议阅读他的文章:
http://haacked.com/archive/2008 /10/23/model-binding-to-a-list.aspx
I would definitely not change the ints to strings. Phil Haack has a great piece on modelbinding to lists - there is some trickery involved when trying to do this, so I would suggest reading his article:
http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx