asp.net mvc - How to send an array items from UI to MVC Controller -


i have array of objects in ui being sent mvc controller . array of objects :

`doorid`,`doorname` , array of `schedules`. `schedules` array has `scheduleid` , `schedulename`. 

enter image description here

now how send mvc controller ? , every doorid , it's associated scheduleid can extracted separately form obeject ?

presently , sending doorid array , scheduleid array separately ,

but not want . want send entire array itself.

   public async task<actionresult> addgroup(string[] doorids, string[] scheduleentity)//accessgroupentity entity, string accountid     {         groupentity groupentity = new groupentity();           var doorschedulelist = new list<doorinfoentity>();          for(int i=0;i< doorids.length;i++)         {             doorschedulelist.add(new doorinfoentity()             {                 doorid = doorids[i],                 scheduleid = scheduleentity[i]              });         }          accessgroupentity.dooritems = doorschedulelist; 

and parse doors[index].doorid , doors[index].scheduleid form 'doorinfoentity` object.

how ?

i tried object[] doors says object not contain definition doorid or scheduleid.

you need object graph in c# modelbinder can bind posted data mimics object graph have in javascript. example:

public class door {     public guid doorid { get; set; }     public string doorname { get; set; }     public list<schedule> schedules { get; set; }     ... }  public class schedule {     public guid scheduleid { get; set; }     ... } 

then, accept root class param in action:

public async task<actionresult> addgroup(list<door> doors) 

the modelbinder, then, create object graph server-side posted data.


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -