0

我在MVC 5中有几个区域,每个区域都有它自己的HomeController。 所以URL看起来像:MVC 5区域隐藏主页控制器在URL中

/domain/{area}/{controller}/{action}/{id} 
/domain/myarea/home/myaction 

是否有可能配置的路由来隐藏每个区域的家居控制器的名字吗?所以URL应该如下所示: /domain/myarea/myaction - 指向当然的区域中的家庭控制器。

谢谢, Alex。

+0

您可以在routeconfig.cs文件中映射新路由。新的路由将只包含action的参数,并确保更具体的路由被放置在routeconfig.cs的最高优先级上 –

回答

0

您应该能够更新区域注册的路由模式以删除控制器名称。

例如:

public class EventsAreaRegistration : AreaRegistration 
{ 
    public override string AreaName 
    { 
     get 
     { 
      return "Events"; 
     } 
    } 

    public override void RegisterArea(AreaRegistrationContext context) 
    { 
     context.MapRoute(
      "Events_default", 
      "Events/{action}/{id}", 
      new { action = "Index", controller = "Home", id = UrlParameter.Optional }, 
      new string[] { "MyProject.Areas.Events.Controllers" } 
     ); 
    } 
} 

现在请求yourSite/Events/Details/23将在您的活动区域返回的HomeController的详细操作方法。