c# - How to populate an array in side a model for postback -


i have model contains list of milestone, want list populated (inside model) given set of textboxes in webpage.

public class project {     public string projectnumber { get; set; }     public ilist<parameter> parameters;     public ilist<milestone> milestonelist = new list<milestone>(); } 

and inside html.beginform("edit", "home", formmethod.post, new { project = model })) have following textbox.

@for (int = 0; < model.milestonelist.count; i++) {       <td style="align-content: center;">@html.textboxfor(model=>model.milestonelist[i].value)</td> } 

my problem in controller below milestonelist null in model project

[httppost] public actionresult edit(project project) {     helper.createproject(project, system.web.httpcontext.current.user.identity.name);     return view(); } 

so how should program list inside model populated through textboxes?

your using fields in model, not properties, defaultmodelbinder cannot set value. change model to

public class project {     public string projectnumber { get; set; }     public ilist<parameter> parameters { get; set; }     public ilist<milestone> milestonelist { get; set; } } 

and initialize collection in in controller.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -