我在partialView中有一个表单
@using (Html.BeginForm(null, null, new { controller = "Module", action="ModuleIndex", module="" }, FormMethod.Get, new { id = "frmMDR" }))
{
@Html.RadioButton("mdrSelector", "Maintenance", false, new { id = "rdoMaintenance" })<label for="rdoMaintenance">M</label>
@Html.RadioButton("mdrSelector", "Diagnostics", false, new { id = "rdoDiagnostics" })<label for="rdoDiagnostics">D</label>
@Html.RadioButton("mdrSelector", "Repair", false, new { id = "rdoRepair" })<label for="rdoRepair">R</label>
@Html.Hidden("hdnVehicle", null, new { id="hdnVehicle"})
}
当我选择单选按钮时,如何使用所选的单选按钮值填充模块参数?我正在使用jQuery在单选按钮更改事件上提交表单。
$(':radio').change(function () {
$('#frmMDR').submit();
});
这是我的控制器方法
public ActionResult ModuleIndex(string module)
{
switch (module)
{
case "Maintenance":
return RedirectToRoute(new { area = module, controller = "Maintenance" });
case "Diagnostics":
return RedirectToRoute(new { area = module, controller = "Diagnostics" });
case "Repair":
return RedirectToRoute(new { area = module, controller = "Repair" });
default:
return RedirectToRoute(new { area = module, controller = "Maintenance" });
}
}
最后这是我的路由配置
routes.MapRoute(
"Module", // Route name
"Module/ModuleIndex/{module}",
new { controller = "Module", action = "ModuleIndex", module = "" }
);
我做得不好?任何提示或帮助总是受到赞赏。
亲切的问候,
〜在圣地亚哥
答案 0 :(得分:0)
根据this msdn网站上的第一个示例,第一个字符串参数必须与控制器参数名称相同:
@Html.RadioButton("module", "Maintenance", false)
@Html.RadioButton("module", "Diagnostics", false)
@Html.RadioButton("module", "Repair", false)