1

我想调查一下我的产品的服务。

1   Was the product or service provided in a timely manner? 
    - Very Satisfied
    - Satisfied
    - Neutral
2   Was the product or service complete and accurate? 
    - Very Satisfied
    - Satisfied
    - Neutral

数据取自数据库,每个选项都用作单选按钮。我在我的 asp.net 项目视图中循环数据:

  <%      
   foreach (var serviceQ in _question)
   {
  %>
      <%:Html.RadioButtonFor(model => model.Option, serviceQ.Option1)%>
      <%:Html.LabelFor(m => m.Option1) %>
      <%:serviceQ.Option1 %>
      <%:Html.ValidationMessageFor(model =>model.Option1) %>

      <%:Html.RadioButtonFor(model => model.Option, serviceQ.Option2)%>
      <%:Html.LabelFor(m => m.Option2) %>
      <%:serviceQ.Option2 %>
      <%:Html.ValidationMessageFor(model =>model.Option2) %>

  <%
   }
  %>

但问题是我这样做我所有的单选按钮都具有相同的名称。

我试过foreach块:

<%:Html.RadioButtonFor(model => model.Option + serviceQ.ID, serviceQ.Option1)%>
<%:Html.RadioButtonFor(model => model.Option + serviceQ.ID, serviceQ.Option2)%>

然后得到一个错误:Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.

4

1 回答 1

1

HtmlHelper.RadioButton Method(String, Object)

public IHtmlString RadioButton(
    string name,
    Object value
)

你会得到这样的东西:

<%:Html.RadioButton(model.Option + serviceQ.ID, serviceQ.Option1)%>
于 2013-02-21T11:22:22.640 回答