2016-11-25 156 views
1

在MVC 5中,我有一个旧的控制器“MyOld”并需要它指向“MyNew”,但请求继续到MyOld。MVC与区域的路由

 routes.MapRoute(
      name: "newthing", 
      url: "Trade/MyOld", 
      defaults: new { controller = "MyNew", action = "Index", area = "Trade" } 
      ).DataTokens.Add("area","Trade"); 

回答

0

您应该添加路由器的方法RegisterArea

TradeAreaRegistration.cs

public class TradeAreaRegistration : AreaRegistration 
{ 
    public override string AreaName 
     { 
      get 
      { 
       return "Trade"; 
      } 
     } 

    public override void RegisterArea(AreaRegistrationContext context) 
    {  
     context.MapRoute(
     name: "MyOldToMyNew", 
     url: "Trade/MyOld", 
     defaults: new { controller = "MyNew", action = "Index", id = UrlParameter.Optional } 
    ); 

     context.MapRoute(
      name: "Trade_default", 
      url: "Trade/{controller}/{action}/{id}", 
      defaults: new { action = "Index", id = UrlParameter.Optional } 
     ); 
    } 
}