How To Change Default View In MVC 4 Web Application

Viewed 11920

By default, MVC 4 in Visual Studio 2017 sets _Layout.cshtml as the default layout for all pages. I believe it's doing this in App_Start/RouteConfig.cs:

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }

(Index is set as the home page)

enter image description here

I'm still not sure how Index is getting _Layout.cshtml. But what if I'm trying to set a different view - a login page - as the home page, like this?

enter image description here

Also I'm trying to get rid of the Reports, Accounts, Settings, and Logout <li>'s in the header so that the page matches the design above. I'll also need a container with a form inside of it.

I've tried creating a _Login view inside of /Home and /Shared and changed "Index" to "Login" in App_Start/RouteConfig.cs:

routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Login", id = UrlParameter.Optional }

enter image description here

But that's giving me an error:

enter image description here

How can I create a view and set that view as the default view for this MVC 4 Web App? Thanks

2 Answers
Related