如何使用ajax传递from.serialize()和数组值?

问题描述 投票:0回答:1

我正在使用serialize将'form'的值从ajax传递到控制器。问题是我的'test'数组是空的,没有从ajax传递值到控制器,我使用ASP.NET MVC 5。请帮助,谢谢

但当我删除模型表格时,测试数组有一个值并传递到控制器。我需要两个参数都传入控制器

var test = [];
test[0] = 1;
test[1] = 2;

function saveSelected() {
    var model = $('form').serialize();

     $.ajax({
        url: '@Url.Action("index", "order")',
        type: 'POST',
        data: { model: model.serialize(), test: test },
        traditional: true,
        success: function (data) {
            alert("success");
        }
    });
}

我的控制器

public ActionResult Index(MyModel model, string[] test)
{
     return View();
}
c# jquery asp.net-mvc asp.net-ajax ajaxform
1个回答
0
投票

你可以使用 data: { model: model, test: JSON.stringify(test)}

© www.soinside.com 2019 - 2024. All rights reserved.