Question

I have three radio buttons and my field value type is integer like Maintenance for 3, Active for 1 and Inactive for 2.

     @Html.RadioButtonFor(model => model.StatusId, "3") Maintenance
     @Html.RadioButtonFor(model => model.StatusId,"1") Active
     @Html.RadioButtonFor(model => model.StatusId, "2") Inactive

i using above code then insert data properly but when my form open in edit mode then i have not get any radio button selected.

and i also used below code but not get success.

  @Html.RadioButtonFor(model => model.StatusId, "3", Model.StatusId == '3' ? new {Checked = "checked"} : null) Maintenance
  @Html.RadioButtonFor(model => model.StatusId, "1",Model.StatusId == '1' ? new {Checked = "checked"} : null) Active}
  @Html.RadioButtonFor(model => model.StatusId, "2",Model.StatusId == '2' ? new {Checked = "checked"} : null) Inactive

so how to get selected radio button in edit mode

thanks in advance

Was it helpful?

Solution

Please try with the below code snippet.

@Html.RadioButtonFor(model => model.StatusId, "2", Model.StatusId == '2' ? new {@Checked = "checked"} : '') 

OR

@Html.RadioButtonFor(model => model.StatusId, "2", Model.StatusId == '2' ? new {@Checked = "checked"} : null) 

If above code is not worked then please provide your rendered html code of this radiobutton/input.

OTHER TIPS

My solution in post Set a RadioButtonFor() checked by default within a Foreach loop will work for you. Use the Model.StatusId == '3' comparison to determine the 'checked' value in the extension method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top