开发者

Routing ASP.NET MVC root application to MVC virtual directory

开发者 https://www.devze.com 2023-04-06 13:22 出处:网络
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 firs

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号