Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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)
     {
         System.Diagnostics.Debug.WriteLine(mass[0].Begin);
     }

how to execute this code? thanks.

share|improve this question
possible duplicate of jQuery Ajax POSTing array to ASP.NET MVC Controller – Meryovi 23 hours ago

3 Answers

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)

share|improve this answer
+1 for good link. The function to be executed is JSON.stringify(x). – Alex Bagnolini Feb 4 '10 at 23:18

try write code as below:

    var option = {
    url: '/Home/Index',
    type: 'POST',
    data:JSON.stringify(request),
    dataType: 'html',
    contentType: 'application/json',
    success: function (result) { alert(result); }
    }; 
$.ajax(option);
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.