Does anyone know how to bind a Yes/No radio button to a boolean property of a Strongly Typed Model in ASP.NET MVC.
Model
public class MyClass
{
public bool Blah { get; set; }
}
View
<%@ Page Title="blah" Inherits="MyClass"%>
<dd>
<%= Html.RadioButton("blah", Model.blah) %> Yes
<%= Html.RadioButton("blah", Model.blah) %> No
</dd>
Thanks
SOLUTION:
Thanks for Brian for the direction but it was the opposite of what he wrote. As so -
<%@ Page Title="blah" Inherits="MyClass"%>
<dd>
<%= Html.RadioButton("blah", !Model.blah) %> Yes
<%= Html.RadioButton("blah", Model.blah) %> No
</dd>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…