简体   繁体   中英

Issue while sending array of objects to server in ASP.NET MVC

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 ?

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"}
]}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM