Reputation: 15
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")
Upvotes: 1
Views: 486
Reputation: 218732
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);
}
Upvotes: 0