Routing ASP.NET MVC root application to MVC virtual directory
I have an MVC application setup as a root application. With in that root dir I have a virtual directory that is also an MVC app. I need to navigate from the root app to the virtual directory. The first hurdle was finding the controller that existed in another namespace, and I was able to do that as follows..
Dim namespaceControllers() As String = {"ExternalAssemblyName"}
routes.MapRoute( _
开发者_运维百科 "virtualroute", _
"ExternalAssemblyName/{controller}/{action}/{id}", _
New With {.controller = "testvir", .action = "Index", .id = ""}, _
namespaceControllers _
)
routes.MapRoute( _
"Default", _
"{controller}/{action}/{id}", _
New With {.controller = "Home", .action = "Index", .id = ""} _
)
It correctly finds the controller, however it still tried to locate the view in the root application, not the virtual dir. If I move the View from the virtual dir to the root dir, it works.
Routes can be tricky. I can't recommend a fix without seeing your application (someone with more experience might be able to), but I can suggest installing the RouteDebugger tool to help with routing issues. It has helped me work out routing issues multiple times.
It's also available as a NuGet package.
精彩评论