【问题标题】:MVC routing issue which I can't find a solution我找不到解决方案的 MVC 路由问题
【发布时间】:2013-04-08 18:29:50
【问题描述】:

我有一个名为 User 的区域。在该区域下,我有一个名为 Index 的视图。

只有一条路线的区域注册:

public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
                "0",
                "user/signup",
                new { action = "Index", controller = "Signup" },
                new string[] { "Company.Web.Areas.User.Controllers" }
            );
}

控制器路径:

Areas\User\Controllers\SignupController.cs

查看路径:

Areas\User\Views\Signup\Index.cshtml

这就是我尝试在带有注册超链接的标头中生成 URL 的方式:

<a href="@Url.Action("Index", "Signup", new { area = "User", returnUrl=ViewContext.HttpContext.Request.Url.PathAndQuery })">Signup</a>

这是我得到的网址: http://www.myserver.com/user/signup?returnUrl=home/main

url 看起来正确,路由只有一个路由。

但是当我点击网址时,它说:找不到资源。用户/注册

我错过了什么?

【问题讨论】:

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


    【解决方案1】:

    试试

    context.MapRoute(
                "signup",
                "{controller}/{action}", // URL with parameters
                new { controller = "Signup", action = "Index" } // Parameter defaults
            );
    

    这应该映射到注册控制器和索引操作

    【讨论】:

      猜你喜欢
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-07
      • 1970-01-01
      • 1970-01-01
      • 2021-06-10
      相关资源
      最近更新 更多