MVC2 Model Binding Enumerables?

Posted by blesh on Stack Overflow See other posts from Stack Overflow or by blesh
Published on 2010-04-28T14:22:58Z Indexed on 2010/04/29 2:57 UTC
Read the original article Hit count: 428

Okay, so I'm fairly new to model binding in MVC, really, and my question is this:

If I have a model with an IEnumerable property, how do I use the HtmlHelper with that so I can submit to an Action that takes that model type.

Model Example:

public class FooModel {
    public IEnumerable<SubFoo> SubFoos { get; set; }
}
public class SubFoo {
    public string Omg { get; set; }
    public string Wee { get; set; }
}

View Snip:

<%foreach(var subFoo in Model.SubFoo) { %>
     <label><%:subfoo.Omg %></label>
     <%=Html.TextBox("OH_NO_I'M_LOST") %>
<%} %>

© Stack Overflow or respective owner

Related posts about asp.net-mvc-2

Related posts about asp.net-mvc