Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Set Default Layout For ASP Razor MVC

I am assuming there is a way to set a default layout to use if one is not selected, but I cant seem to find any documentation on it.

From the controller, if I call return View() it returns the page without any of the html from the layout. If i return the view as follows, the layout shows up fine.

return View("Index", "~/Views/Shared/_PublicLayout.cshtml");

So I'm wondering if there is a way to set the default variable for the layout so i don't have to specify it every time for every view.

like image 402
Dan Hastings Avatar asked Apr 11 '16 11:04

Dan Hastings


1 Answers

In the views folder locate or create file _ViewStart.cshtml and inside you can define:

@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}

where _Layout.cshtml is your default layout.

like image 135
Lesmian Avatar answered Oct 06 '22 23:10

Lesmian