c# - pass list of objects from view to controller in asp.net -


i adding checkboxes every object in list. when try return values controller list empty , checkbox bool.

can explain me how pass list correctly view controller.

i tried form not sure if correct way.

i searched lot on google , found similar posts on stackoverflow couldn't find 1 helped me.

view

@model list<wcfasp.net.wcf.person>  @{     viewbag.title = "showview"; }  @using (html.beginform("check", "home")) {         (int = 0; < model.count(); i++)         {         <p>@html.checkboxfor(m => m[i].ischecked) @html.displayfor(m => m[i].name)</p>         }         <input id="submit" type="submit" value="submit" /> } 

controller

[httppost]         public actionresult check(list<wcf.person> selectedpersonlist)         {             //here empty list              return view("showselectedview");         } 

person

[datacontract]     public class project     {         [datamember]         public string name { get; set; }         [datamember]         public bool ischecked { get; set; }          public project(string name, bool ischecked)         {             this.name = name;             this.ischecked = ischecked;         }     } 

little question @ end. getting down voted because not pro or there reason?

if want more properties populated within list can use hidden fields store information:

for (int = 0; < model.count(); i++) {     @html.hiddenfor(m => m[i].name)     <p>@html.checkboxfor(m => m[i].ischecked) @html.displayfor(m => m[i].name)</p> } 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -