【问题标题】:Binding Monorail RadioFields to GenericLists将 Monorail RadioFields 绑定到 GenericLists
【发布时间】:2009-09-08 19:33:55
【问题描述】:

在我的视图中,我有以下对象绑定到表单:

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

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

我将这些信息作为各种 RadioField 组呈现给用户。

如何绑定 RadioField 以便它们为 Items 中的每个项目显示一组 RadioField。每组 RadioFields 对每条 Lines 都有一个选项,并且每组 RadioFields 都绑定到 Resolution?

【问题讨论】:

    标签: castle-monorail castle


    【解决方案1】:

    这是一个普通的 HTML 问题

    <% 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>
    <% } %>
    

    【讨论】:

      猜你喜欢
      • 2023-03-16
      • 2010-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-08
      相关资源
      最近更新 更多