2010-05-08 11 views
5

W mojej aplikacji mam kontroler o nazwie Snippets zarówno w obszarze domyślnym (w katalogu głównym aplikacji), jak iw moim obszarze o nazwie Manage. Używam T4MVC i niestandardowych tras, tak:T4MVC i nazwy kontrolerów duplikatów w różnych obszarach

routes.MapRoute(
    "Feed", 
    "feed/", 
    MVC.Snippets.Rss() 
); 

i dostaję ten błąd:

Multiple types were found that match the controller named 'snippets'. This can happen if the route that services this request ('{controller}/{action}/{id}/') does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of the 'MapRoute' method that takes a 'namespaces' parameter.

The request for 'snippets' has found the following matching controllers: Snippets.Controllers.SnippetsController Snippets.Areas.Manage.Controllers.SnippetsController

Wiem, że istnieją przeciążenia dla MapRoute że brać namespaces argumentu, ale nie ma takich przeciążeń z Obsługa T4MVC. Może być, że czegoś brakuje? Ewentualny składnia może być:

routes.MapRoute(
    "Feed", 
    "feed/", 
    MVC.Snippets.Rss(), 
    new string[] {"Snippets.Controllers"}   
); 

lub wydaje się całkiem dobry dla mnie, aby mieć przestrzeń nazw jako własność T4MVC:

routes.MapRoute(
    "Feed", 
    "feed/", 
    MVC.Snippets.Rss(), 
    new string[] {MVC.Snippets.Namespace}   
); 

Z góry dzięki!

Odpowiedz

5

sens. Domyślam się, że jesteś pierwszym, który do tego doszedł. Spróbuj wymienić wszystkie metody MapRoute w T4MVC.tt brzmienie:

public static Route MapRoute(this RouteCollection routes, string name, string url, ActionResult result) { 
     return MapRoute(routes, name, url, result, null /*namespaces*/); 
    } 

    public static Route MapRoute(this RouteCollection routes, string name, string url, ActionResult result, object defaults) { 
     return MapRoute(routes, name, url, result, defaults, null /*constraints*/, null /*namespaces*/); 
    } 

    public static Route MapRoute(this RouteCollection routes, string name, string url, ActionResult result, string[] namespaces) { 
     return MapRoute(routes, name, url, result, null /*defaults*/, namespaces); 
    } 

    public static Route MapRoute(this RouteCollection routes, string name, string url, ActionResult result, object defaults, object constraints) { 
     return MapRoute(routes, name, url, result, defaults, constraints, null /*namespaces*/); 
    } 

    public static Route MapRoute(this RouteCollection routes, string name, string url, ActionResult result, object defaults, string[] namespaces) { 
     return MapRoute(routes, name, url, result, defaults, null /*constraints*/, namespaces); 
    } 

    public static Route MapRoute(this RouteCollection routes, string name, string url, ActionResult result, object defaults, object constraints, string[] namespaces) { 
     // Start by adding the default values from the anonymous object (if any) 
     var routeValues = new RouteValueDictionary(defaults); 

     // Then add the Controller/Action names and the parameters from the call 
     foreach (var pair in result.GetRouteValueDictionary()) { 
      routeValues.Add(pair.Key, pair.Value); 
     } 

     var routeConstraints = new RouteValueDictionary(constraints); 

     // Create and add the route 
     var route = new Route(url, routeValues, routeConstraints, new MvcRouteHandler()); 

     if (namespaces != null && namespaces.Length > 0) { 
      route.DataTokens = new RouteValueDictionary(); 
      route.DataTokens["Namespaces"] = namespaces; 
     } 

     routes.Add(name, route); 
     return route; 
    } 

pamiętać, że można uzyskać silną wpisywanie na przestrzeni nazw kontrolera bez pomocy T4MVC jest po prostu pisząc:

string[] { typeof(MyApplication.Controllers.SnippetsController).Namespace } 

należy dodać, że idealnie, nie musiałby przejść Przestrzenie nazw w ogóle, ponieważ swoim zamiarze ukierunkowana na konkretną kontroler jest już zrobione w MVC.Snippets.Rss() rozmowy. Jednak nie mogłem znaleźć oczywistego sposobu, aby to działało bez dużych zmian w T4MVC.

Zresztą, proszę sprawdzić i przetestować zmiany, i daj mi znać, jak to działa dla Ciebie. Jeśli wygląda dobrze, będę miał go w.

Dzięki!

Powiązane problemy