說明:開發環境 vs2012 asp.net mvc4 c#
1、HTML前端代碼
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ArrayTest.aspx.cs" Inherits="MvcAppTest.ArrayTest" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script src="ewJS/jquery.js"></script>
<script type="text/javascript">
var ids = []; $(function () { for (var i = 0; i < 20;i++) { var item = i + 1; ids.push(item); } $.ajax({ url: 'Home/RemoveUser', data: { ids: ids.join(',') }, type: "post", dataType: 'json', success: function (d) { } }); }); </script>
</head>
<body>
</body>
</html>
2、后台代碼
[HttpPost] public ActionResult RemoveUser() { var ids = Request["ids"].ToString(); var result = new ResultViewModel(); try { if (!String.IsNullOrEmpty(ids)) { string[] pids = ids.Split(','); } result.success = true; result.msg = "刪除成功!"; } catch { result.success = false; result.msg = "刪除失敗!"; } return Json(result); }