Alex Rivera | Logout

Why is my View not including _Layout.cshtml?

Asked 2011-10-14T12:29:10.200
22

I recently made some changes to my MVC 3 project.

When I run it, the Views dont include any files like Site.css. When I debug my Index() ActionController, it jumps directly to the View, withouting including files like _Layout.cshtml. So i just get a View with a white background, no menus etc.

The Global.asax.cs file contains following code:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

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

    routes.MapRoute(
        "Default2", // Route name
        "{controller}/{action}/{id}/{page}", // URL with parameters
        new { controller = "Survey", action = "DisplayQuestions", id = "", page = "" }
    );
}
Edit
Report

1 Answer

2

Move your "Default2" route up above your "Default" route.

the Default route is more generic so Default2 should be first

also, inside your views make sure that you're specifying the layout to use

@{
    Layout = "yourlayoutpage.cshtml"
}
answered 2011-10-14T12:30:59.950

Your Answer