2016-11-25 3 views
1

In MVC 5 habe ich einen alten Controller "MyOld" und muss es auf "MyNew" zeigen, aber die Anforderung wird weiterhin MyOld gehen.MVC Route mit einem Bereich

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

Antwort

0

Sie sollten Router Methode hinzufügen 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 } 
     ); 
    } 
}