asp.net-mvc-3 – 带区域的MVC – Html.ActionLink返回错误的URL /路由?

我正在使用MVC3并在我的应用程序中有区域.一般来说,一切正常,我可以导航到我的区域(例如Admin = Area,Controller = Department),如下所示:
<%: Html.ActionLink("Departments","DepartmentIndex","Department",new { area = "Admin"},null )%>

但是,我注意到的是,如果我没有在ActionLink中指定区域,例如

<%: Html.ActionLink("Test","Index","Home")%>

如果我已导航到“管理员”区域,这将停止工作.即我的网址现在
http://localhost/myproj/Admin/Home/Index
代替
http://localhost/myproj/Home/Index

关于这里发生了什么的任何想法?

创建MVC应用程序/区域时,我的路由是所有认值.即

public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "Default",// Route name
            "{controller}/{action}/{id}",// URL with parameters
            new { controller = "Home",action = "Index",id = UrlParameter.Optional },new[] { "MyProj.Controllers" } 
        );
    }

我的区域注册

public override void Registerarea(AreaRegistrationContext context)
    {
        context.MapRoute(
            "Admin_default","Admin/{controller}/{action}/{id}",new { action = "Index",id = UrlParameter.Optional }
        );
    }

这是设计的吗?
该帖子建议使用RouteLink而不是ActionLink:
说使用RouteLink
Is it required to have “area” routevalue on actionlink if the application was grouped into areas?

解决方法

This StackOverflow answer正确地指出,如果您正在使用区域,则需要提供区域名称.

例如.

Html.ActionLink("Home","Home",new { Area = "" },new { })

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....