前端Js传递数组至服务器端
$("#delete").click(function () { var ID = ""; var ary = []; var bb = document.getElementsByName("PersonId"); $('input:checkbox[name="PersonId"]:checked').each(function () { ary.push($(this).val()); }); if (ary.length == 0) { alert("请选择至少一条"); } else { $.ajax({ type: "POST", url: "@Url.Content("~/User/BatchDelete")", contentType: "application/json;charset=utf-8", dataType: "json", data: JSON.stringify(ary), success: function (data) { var i = 0; $('input:checkbox[name="PersonId"]:checked').each(function () { window.location.reload(); }); } }); } });
服务器端(asp.net mvc controller)
[HttpPost] public async Task<ActionResult> BatchDelete(string[] ary) { foreach (var id in ary) { } return Json(" "); }