views:

273

answers:

1

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 Index Controller

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

    [AcceptVerbs(HttpVerbs.Post)]        
    public ActionResult Index(            
        string DateStart,            
        MyClass []mass
        )
    {
        Sys

tem.Diagnostics.Debug.WriteLine(mass[0].Begin);
        }

how execute this code? thanks

+2  A: 

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)

Paul Creasey
+1 for good link. The function to be executed is `JSON.stringify(x)`.
Alex Bagnolini
Thanks!, It's magic)
mola10