在asp.net mvc中从ajax到actionresult的数组的空ID

发布于 2024-12-18 04:13:41 字数 954 浏览 3 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谁人与我共长歌 2024-12-25 04:13:41

您可以在 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]

旧瑾黎汐 2024-12-25 04:13:41

我绝对不会将整数更改为字符串。 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文