asp.net mvc - Unable to model bind a collection within a view model -


i have view so:

@model foo  @html.displayfor(model => model.fooname);  @{   int counter = -1;   } @foreach(var bar in model.bars) {   counter++;   <tr>     <td><span name = "bars[@counter].barname">@bar.barname</span></td>   </tr> } 

where:

class foo {   public string fooname { get; set; }    public icollection<bar> bars { get; set; } }  class bar {   public string barname { get; set; } } 

even though view has right, when post foo, though, doesn't post bars.

public actionresult dostuffwithfoo(foo foo) {   debug.assert(foo.bars != null); // fails } 

i have omitted unnecessary , obvious parts question such mark of table.

you should understand on form post post values in inputs should this:

@for(var = 0; < model.bars.count(); i++) {   <tr>     <td><span>@html.textboxfor(x=> model.bars[i].barname)</span></td>   </tr> } 

html.textboxfor helper create input can post controller.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -