Search code examples
castle-monorailcastle

Binding Monorail RadioFields to GenericLists


I have the following object which I bind to a Form in my view:

public class Foo
{  
    public List<Bar> Items { get; set; }
}

public class Bar
{
    public List<string> Lines { get; set; }
    public int Resolution { get; set; }
}

I am presenting this information to the user as various groups of RadioFields.

How do I bind the RadioFields so that they display a group of RadioFields for each item in Items. Each group of RadioFields having an option for each Lines and that each group of RadioFields is bounded to Resolution?


Solution

  • It's a plain old HTML question

    <% foreach (var bar in view.Foo.Items) { %>
       <% var barIx = 0; %>
    <fieldset>
       <% foreach (var line in bar.Lines) { %>
         <% var lineIx = 0; %>
       <label for="bar<%=barIx%>_line_<%=lineIx%>"><%=line%>: </label>
       <input type="radio" value="<%=line%>" name="bar[<%=barIx%>].Lines" id="bar<%=barIx%>_line_<%=lineIx%>" />
         <% ++lineIx; %>
       <% } %>
       <label for="bar<%=barIx%>_resolution">Resolution: </label>
       <input type="text" value="<%=bar.Resolution%>" name="bar[<%=barIx%>].Resolution" id="bar<%=barIx%>_resolution" />
       <% ++barIx; %>
    </fieldset>
    <% } %>