我真的很希望能够做到这一点我该如何判断一个单选按钮是否被选中? (MVC)
if myRB.Checked = true then
return redirecttorout("SomeRoute")
else
someother route
我习惯的网络形式,在此我可以在代码中做到这一点的背后
我真的很希望能够做到这一点我该如何判断一个单选按钮是否被选中? (MVC)
if myRB.Checked = true then
return redirecttorout("SomeRoute")
else
someother route
我习惯的网络形式,在此我可以在代码中做到这一点的背后
的mvc像普通的HTML后返回值通过输入的名称不是id。在单选按钮集合中,所有单选按钮具有相同的名称。所以,你的东西拿回来与所选择的单选按钮的值的单选按钮的名称
的代码最终看起来像
如果(model.radio ==“VA1”) { ... }
在表单发布给您的操作中,需要创建一个字符串var来保存值。
public ActionResult GetRadioButtonValue(string RadioButtonVal)
{
单选按钮的名称都需要匹配的观点,但价值会是什么被发送到行动。确保如上所示的字符串与单选按钮的名称相匹配。检查该字符串为空还是空也是一个好主意。
string.IsNullOrEmpty(RadioButtonVal)
查看
@model MvcApplication2.Models.CountryModel
@using (Html.BeginForm())
{
@Html.RadioButton("Gender", "Male" new { @checked = "checked" }) Male
@Html.RadioButton("Gender", "Female")Female
<input type="submit" text="submit"/>
}
模型
public class CountryModel
{
public string Gender{ get; set; }
}
控制器
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(CountryModel model)
{
//for radio button
CountryModel dd = new CountryModel();
string date1 = model.RDB;
return View(model);
}
好吧,如果你想使用mvc,你最好开始做一些教程,书籍等。 – Omu 2010-10-04 18:21:21