简体   繁体   English

如何检查Html.radiobuttonfor

[英]How to check Html.radiobuttonfor

I have three radio buttons like the following code in my MVC project. 我的MVC项目中有三个单选按钮,如下面的代码。

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 ) 我已经在Session中保存了用户的响应(如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")

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 如果要在页面加载时预先选择特定的单选按钮,可以在GET操作中进行设置

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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM