How to check Html.radiobuttonfor

480 Views Asked by At

I have three radio buttons like the following code in my MVC project.

I need to check one of them when user come back to the page through a back button in my application.

I already save the user's response in Session (like Session ("MyField") = model.MyField)

Can you please help me how I can do that?

@Html.RadioButtonFor(model => model.MyField, "Yes")
@Html.RadioButtonFor(model => model.MyField, "No")
@Html.RadioButtonFor(model => model.MyField, "NA")
1

There are 1 best solutions below

4
Shyju On BEST ANSWER

Usually when you click the browser back button, you will be able to see the input field items with previously submitted data.

If you want to pre select a specific radio button when the page loads, you can set this in your GET action

public ActionResult Create()
{
   var vm= new YourViewModel();
   vm.MyField = "No";  // Replace this hard coded value with whatever value you want to set
   return View(vm);
}