0
votes

I have a subsite within my main site for site Administration. The site is physically stored in the form

~/Views/Administration/ViewName/Index

With controllers inside

~/Controllers/Admin/ControllerName

I am getting an exception trying to visit the page.

The view 'index' or its master was not found or no view engine supports the searched locations. The following locations were searched: ~/Views/ViewName/index.aspx ~/Views/ViewName/index.ascx ~/Views/Shared/index.aspx ~/Views/Shared/index.ascx ~/Views/ViewName/index.cshtml ~/Views/ViewName/index.vbhtml ~/Views/Shared/index.cshtml ~/Views/Shared/index.vbhtml

I added a route

        routes.MapRoute(
                "Administration", // Route name
                "Administration/{controller}/{action}/{id}", // URL with parameters
                new { controller = "Administration", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );

Going directly to the page manually

http://localhost:999/Administration/BaseItem/index

Does not result in exception, but I get no content. This leads me to believe it is not finding the View. What am I doing wrong?


I think the issue is that I have told the route engine how to route to the Controller, but I have not told the system how to route to the View. Where do I tell the system where the views are?
1
Is that maproute the first one in the global.asax or have you put it after the default? (If so the default is likely matching first...)Timbo
@Timbo It comes after. I changed it to before. I still get a blank screen, but I'm not seeing any errors.P.Brian.Mackey
Cool, yep, the default was matching it before then. You have to order your config as most specific to least specific. I think the blank screen sounds like a separate issue.Timbo
@Timbo - Apologies, actually the errors are still there. They just showed up in my email late (I catch and throw out emails in global.asax).P.Brian.Mackey
it looks like it is treating "ViewName" as the controller, hence the feeling that it's a routing issue. In the /Administration/BaseItem/Index url you should be resolving a controller called BaseItem and a view called Index, found in ~/Views/BaseItem/Index, if the routemaps are right. Is that the correct structure of your controller / views?Timbo

1 Answers

3
votes

The problem is not with the routes, but with the design. The view engine cannot find your view, because it cannot find the correct path, since the default view engines are not designed to search for a subsite.

Instead of creating a subsite, make Administration an Area in your project. In AdministrationAreaRegistration.cs, you will set a route similar to the route you added. Place your views in the Views folder inside the Administration folder (inside the Area folder), and everything will work properly.