http://blog.csdn.net/lonestar555/article/details/10192595/
- // 方式一
- var _list = {};
- for (var i = 0; i < checkedRow.length; i++) {
- _list["selectedIDs[" + i + "]"] = checkedRow[i].ID;
- }
- $.ajax({
- url: '@Url.Action("SetCallBackStatus")',
- //data: { "selectedIDs": _list },
- data: _list,
- dataType: "json",
- type: "POST",
- //traditional: true,
- success: function (responseJSON) {
- // your logic
- alert('Ok');
- }
- });
在action中的参数以数组方式接收数据
一、表单方式
1、提交Form
- <form action="../../test/test" method="post">
- <select name="list_Number" id="list_Number" size="10" multiple="multiple">
- <option value="4">04</option>
- <option value="2">02</option>
- <option value="3">03</option>
- </select>
- </form>
- [HttpPost]
- public ActionResult Test(string[] listNumber){
- return View();
- }
提交前必须选择所有列表:
- $("#list_LotteryNumber > option").attr("selected", true);
2、ajax提交
在ajax的data参数中加上:
- $("form").serialize()
- data: $("form").serialize(),
二、ajax提交数组参数
- var parm = {
- capital: "capital",
- arr: [ "c1","c2", "c3"],
- data: Math.random()
- };
- var p2 = $.param(parm, true);
- // 或 var parm3 = "arr=c1&arr=c2&arr=c3&data=" + Math.random();
- // debugger
- $.ajax({
- type: "post",
- url: '/Home/AjaxArray',
- async: false,
- data: p2,
- success: function (data, txtStatus) {
- alert(" 成功!");
- }
- });
- [HttpPost]
- public ActionResult AjaxArray(string data , List<string> arr)
- {
- ViewBag.Message = "提交数组参数。";
- return Json("");
- }