简体   繁体   中英

Radio Button Group in ASP.NET MVC3

I am having a field of Boolean in Model named Child_With_Bed .

图片

Now, I want radio button group in which yes = true and no = false. So when I select it Child_With_Bed 's value is set.

I tried below code but it is not getting bind with my model.

<tr>
  <th>
     <%: Html.LabelFor(model => model.Child_With_Bed)%>
  </th>
  <td>
     <%: Html.RadioButton("child", Model.Child_With_Bed)%> Yes 
     <%: Html.RadioButton("child", !Model.Child_With_Bed)%> No 
  </td>
</tr>

I don't know how to do this. Please help. Thanks in Advance.

Try this:

<% foreach (var item in Model)
    {
        Html.RadioButtonFor(m => m.item, "Yes")%>
         Yes
        <% @Html.RadioButtonFor(m => m.item, "No")%>
          No
  <%  }%>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM