KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I believe this question applies to any of the "For" Html helpers, but my specific problem is using CheckBoxFor... I have a model that is of type IEnumerable, where rights is a simple POCO. This model is actually a property of a bigger model that I created an EditorTemplate for. Here is the bigger picture of my model: public class bigmodel { public string Title {get; set;} public string Description {get; set;} [UIHint("ListRights")] public IEnumerable<rights> Rights {get;set;} } public class rights { public bool HasAccess {get; set;} public string Description {get;set;} } I created an editortemplate called "ListRights" that my main view uses. For example: <%=Html.EditorFor(m => m.Rights) %>. In ListRights.ascx, I want code like this: <table> <% foreach(rights access in Model) { %> <tr> <td> <%=Html.CheckBoxFor( access ) %> </td> <td> <%=access.Description %> </td> </tr> <% } %> </table> I know the CheckBoxFor line does not work, but I want to do something that generates the same result, as if access was a property on the model. In the above example, I would like everything to autobind on post. I've tried faking the CheckBox with code similar to this, but it doesn't autobind: <table> <% for(int i=0; i < Model.Count(); i++) { %> <tr> <td> <%=Html.CheckBox(string.Format("[{0}].HasAccess",i), Model.ElementAt(i).HasAccess)%> </td> <td> <%=access.Description %> </td> </tr> <% } %> </table> Any suggestions?
Tags (comma-separated)
Save Edits
Cancel