In my application I have controller named Snippets
both in default area (in application root) and in my area called Manage
. I use T4MVC and custom routes, like this:
routes.MapRoute(
"Feed",
"feed/",
MVC.Snippets.Rss()
);
And I get this error:
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
I know that there are overloads for MapRoute
that take namespaces
argument, but there are no such overloads with T4MVC support. May be I'm missing something? The possible syntax can be:
routes.MapRoute(
"Feed",
"feed/",
MVC.Snippets.Rss(),
new string[] {"Snippets.Controllers"}
);
or, it seems quite good to me to have namespace as T4MVC property:
routes.MapRoute(
"Feed",
"feed/",
MVC.Snippets.Rss(),
new string[] {MVC.Snippets.Namespace}
);
Thanks in advance!
Makes sense. I guess you're just the first one to run into this. Try replacing all the MapRoute methods in T4MVC.tt by the following:
Note that you can get strong typing on the controller namespace without T4MVC's help simply by writing:
I should add that ideally, you would not have to pass the Namespaces at all, since your intent to target a specific controller is already captured in the MVC.Snippets.Rss() call. However, I couldn't find an obvious way to make this work without big changes to T4MVC.
Anyway, please review and test the change, and let me know how it works for you. If it looks good, I'll get it in.
Thanks!