【问题标题】:asp.net MVC custom routingasp.net MVC 自定义路由
【发布时间】:2011-05-20 09:10:12
【问题描述】:

您好,我在代码中使用了这两行代码:

using (Ajax.BeginForm("Login", "Users", new { command = "Login"}, new AjaxOptions() { UpdateTargetId = "divLoginPopupContent" }, new { id = "loginPopup" }))
{
    /// some html with submit button

    // and also have following:
    <%= Html.ActionLink("Forgot your password", "Login", "Users", new { command = "ForgotPassword" }, null)%>
}

这是我的地图路线

routes.MapRoute(
                "Users",
                "Users/{command}",
                new { controller = "Users", action = "Login" }
            );

这是控制器动作:

public ActionResult Login(LoginModel model, string command)
     {
          /// some actions
     }

但我不知道我在这里做错了什么......我希望 ActionLink 和 BeginForm 都被路由到这个控制器操作。

【问题讨论】:

  • 嗯..你面临什么样的错误?我刚刚使用了您的代码的 sn-ps,一切看起来都不错.. 使用 actionlink 和提交按钮,我被正确地路由到使用适当命令的登录操作...
  • 因为我的参数中有模型,所以它不会带我去那个动作......
  • 并给我这个错误 HTTP 404。您正在寻找的资源(或其依赖项之一)可能已被删除、更改名称或暂时不可用。请检查以下 URL 并确保其拼写正确。

标签: asp.net-mvc url-routing asp.net-mvc-routing


【解决方案1】:

回答我自己的问题:

我还没有定义另一个路由集合变量,即应该声明命令,像这样

routes.MapRoute(
                "Users",
                "Users/{command}",
                new { controller = "Users", action = "Login", 
                command = Parameter.Optional }
            );

【讨论】:

    猜你喜欢
    • 2011-04-02
    • 2020-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-22
    • 2014-02-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多