Asp.net的mvc阿贾克斯JSON(post数组)数组、mvc、net、Asp

2023-09-10 13:46:09 作者:日韩潮 ≈- Dunabe

JavaScript的\ jQuery的:

javascript\jQuery:

 var items = new Array();

 var obj { Begin: "444", End: "end" };

 items.push(obj);
 items.push(obj);

  var request = {
             DateStart: $("#DateStart").val(),
             mass: items
         };


 $.post("/Home/Index", request, null,
 "json");

C#的mvc指数控制器

C# Mvc Index Controller

 public class MyClass
     {
        public string Begin;
        public string End;
     }

     [AcceptVerbs(HttpVerbs.Post)]        
     public ActionResult Index(            
         string DateStart,            
         MyClass []mass)
     {
         System.Diagnostics.Debug.WriteLine(mass[0].Begin);
     }

如何执行此code?谢谢。

how to execute this code? thanks.

推荐答案

U可以不通过质量:项目,并期望它能够自动序列化为一个JSON数组,你要么需要迭代和构建JSON(坏的计划),或使用 JSON库(好的计划)

U can't pass mass: items and expect it to be serialized as a JSON array automatically, you will need to either iterate and construct the JSON (bad plan) or use a JSON library(good plan)