【问题标题】:MVC routing issue, need help to insert parameterMVC路由问题,需要帮助插入参数
【发布时间】:2010-12-14 22:58:58
【问题描述】:

我在部分视图中有一个表单

     @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 = "" }
          );

我做错了什么?任何提示或帮助都将受到赞赏。

亲切的问候,
~ck 在圣地亚哥

【问题讨论】:

    标签: asp.net-mvc asp.net-mvc-3 razor asp.net-mvc-routing partial-views


    【解决方案1】:

    根据thismsdn 站点上的第一个示例,第一个字符串参数必须与控制器参数名称相同:

    @Html.RadioButton("module", "Maintenance", false)
    @Html.RadioButton("module", "Diagnostics", false)
    @Html.RadioButton("module", "Repair", false)
    

    【讨论】:

    • 是的,这很好用。非常感谢你。我还必须在我的 routevlaues 中删除模块令牌。无论如何,非常感谢。
    • 当时我无法将其标记为正确,因为我刚刚提出了这个问题。但是,是的,您的答案是正确的,我将其标记为正确的。再次感谢朋友! :)
    猜你喜欢
    • 1970-01-01
    • 2010-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-01
    • 2014-09-12
    相关资源
    最近更新 更多