MVC routing issue, need help to insert parameter
I have a form in a 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"})
}
When I choose a radio button, how can I populate the module parameter with the selected radio buttons value? I'm using jQuery to submit the form on the radio buttons change event.
$(':radio').change(function () {
$('#frmMDR').submit();
});
Here is my controller method
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" });
}
}
and lastly here is my routing config
routes.MapRoute(
"Module", // Route name
"Module/ModuleIndex/{module}",
new { controller = "Module", action = "ModuleIndex", module = "" }
);
What am I not doing correctly? Any tips or help is always appreciated.
Kind Regards,
~ck in San DiegoAccording to the first example on this msdn site, the first string argument must be the same as the controller argument name:
@Html.RadioButton("module", "Maintenance", false)
@Html.RadioButton("module", "Diagnostics", false)
@Html.RadioButton("module", "Repair", false)
精彩评论