0

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

Image

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.

1 Answer 1

1

Try this:

<% foreach (var item in Model)
    {
        Html.RadioButtonFor(m => m.item, "Yes")%>
         Yes
        <% @Html.RadioButtonFor(m => m.item, "No")%>
          No
  <%  }%>
Sign up to request clarification or add additional context in comments.

5 Comments

I am not getting How I implement it. I am not using razor and I have boolean field, how could I loop through it?
Just one question. Here Model will be class, So do I have to make a separate class for child_with_bed ?
i think child_with_bed is field of your Model? yes?
yES. and it is of boolean type.
then you can use, m=> m.child_with_bed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.