ASP.NET MVC 2: HtmlHelpers, foreach?

Posted by dcolumbus on Stack Overflow See other posts from Stack Overflow or by dcolumbus
Published on 2011-01-07T19:49:37Z Indexed on 2011/01/07 19:53 UTC
Read the original article Hit count: 207

Filed under:
|
|

This one is new to me... I'm bringing in a Model that represents a list of items. Some items should be rendered as a number of checkboxes and radios. Others will be rendered in a list.

Now I know how to foreach the items and spit them out manually... but I'd like to be able to check them against the Model that I have, making sure that at least one optios is selected/chosen. And obviously display the associated validation errors.

This is how I am displaying the checkbox items manually:

 <ul>
 <% foreach (Corporate.Entities.DesignLayout.Tag tag in Model.DesignOptions.Items)
    { %>
    <li><input type="checkbox" /><%: tag.TagName %></li>
 <% } %>
 </ul>

Two questions arise:

1) How do I check that list of checkboxes against my model? 2) How would I render the tag items with an HtmlHelper SelectList? Example:

<%: Html.ListBoxFor(m=>m.DesignOptions, [don't know what I should put here]) %>

© Stack Overflow or respective owner

Related posts about asp.net-mvc-2

Related posts about models