Basically I want my radio buttons to be checked depending on a value from my model view control, below is some sample code and my attempt so far:
<tr>
<td>
<label for="brakepads" class="label3">Brake Pads:</label></td>
<%= Html.TextBox("brakepads", Model.brakepads, new {style="display:none" })%>
<%= Html.ValidationMessage("brakepads", "*") %>
<td><label for="brakefluid" class="label4" >Passed:</label>
<asp:RadioButton ID="RadioButton15" runat="server" GroupName="b" value="True" Checked="<%= Model.brakepads.Value %>" onclick="brakepads.value=(this.value)" /></td>
<td><label for="brakefluid" class="label4" >Failed:</label>
<asp:RadioButton ID="RadioButton16" runat="server" GroupName="b" value="False" Checked="<% Model.brakepads.Value %>" onclick="brakepads.value=(this.value)"/></td>
</tr>
I get the following at runtime: Cannot create an object of type ‘System.Boolean’ from its string representation ‘<%= Model.brakepads.Value %>’ for the ‘Checked’ property.
I tried using (bool) to cast, but that didn’t work either, so I’m unsure of what to do next. My only concern is that occasionally the bool will be null, if that won’t break functionality then it’s fine.
Either you use
Html.RadioButtonor have another MVC hidden field and bindModel.brakepadsto it. Usejavascriptto set radio button’s Checked property.