JS 怎么把數組類型的參數傳遞到后台,后台怎么獲取


說明:開發環境 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); }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM