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