how to set radio button checked in edit mode in MVC razor view
Don't do this at the view level. Just set the default value to the property in your view model's constructor. Clean and simple. In your post-backs, your selected value will automatically populate the correct selection.
For example
public class MyViewModel
{
public MyViewModel()
{
Gender = "Male";
}
}
<table>
<tr>
<td><label>@Html.RadioButtonFor(i => i.Gender, "Male")Male</label></td>
<td><label>@Html.RadioButtonFor(i => i.Gender, "Female")Female</label></td>
</tr>
</table>
You have written like
@Html.RadioButtonFor(model => model.gender, "Male", new { @checked = true }) and
@Html.RadioButtonFor(model => model.gender, "Female", new { @checked = true })
Here you have taken gender as a Enum
type and you have written the value for the radio button as a string
type- change "Male" to 0 and "Female" to 1.