0

I am working on an application using ASP.NET MVC 4. I am trying to send and array of objects to the controller. My view contains:

<input type="hidden" id="1" name="Persons" value='[
 {"Id":1,"Name":"Abc","Description":"this is desc"},
 {"Id":2,"Name":"def","Description":"this is desc"},         
 {"Id":4,"Name":"ghi","Description":"this is desc"}]'
/>

And my controller action is like this:

public ActionResult create(List<Person> Persons)
{
  //Here the Persons count is always 0, why ?
} 

When i post my form, i always get Persons count 0. Can anybody please help me with this issue ?

tereško
  • 58,060
  • 25
  • 98
  • 150
user1740381
  • 2,121
  • 8
  • 37
  • 61
  • possible duplicate of [How can I post an array of string to ASP.NET MVC Controller without a form?](http://stackoverflow.com/questions/309115/how-can-i-post-an-array-of-string-to-asp-net-mvc-controller-without-a-form) – Dustin Davis Apr 21 '13 at 05:02
  • @DustinDavis thanks for response but i do not want to send my array with ajax. I want to send it with form. – user1740381 Apr 21 '13 at 05:04
  • 2
    Read this http://www.hanselman.com/blog/ASPNETWireFormatForModelBindingToArraysListsCollectionsDictionaries.aspx – Mate Apr 21 '13 at 05:17

1 Answers1

0

Try changing your input value to:

{Persons: [
    {"Id":1,"Name":"Abc","Description":"this is desc"},
    {"Id":2,"Name":"def","Description":"this is desc"},         
    {"Id":4,"Name":"ghi","Description":"this is desc"}
]}
Konstantin Dinev
  • 34,219
  • 14
  • 75
  • 100