asp.net MVC 自定义路由

发布于 2024-11-08 19:10:38 字数 805 浏览 5 评论 0原文

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

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 都被路由到这个控制器动作。

Hi I am using this two lines in my code:

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)%>
}

and this is the map route i have

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

and this is the controller action:

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

but I don'y what I am doing wrong here ... I want ActionLink and BeginForm both to be routed to this controller action.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

向日葵 2024-11-15 19:10:39

回答我自己的问题:

我还没有定义另一个路由集合变量,即应该声明命令,如下所示

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

answering my own question:

i haven't define another route collection variable i.e. command should be declared, like this

routes.MapRoute(
                "Users",
                "Users/{command}",
                new { controller = "Users", action = "Login", 
                command = Parameter.Optional }
            );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文