Answer: In the default template of ASP.NET MVC, we get _ViewStart.cshtml page that is used to almost similar to MasterPage in ASP.NET Web Form or like a layout template.
The code of ViewStart executes before the actual view code executes. By default, _ViewStart template is applied to all view files of this or any sub directory under this directory.
The _ViewStart.cshtml file contains following code.
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
As this code runs before any view code so we have flexibility to specify a different Layout for a particular view.
Because this code runs before any view, a view can override the Layout property and choose a different
one.
Asked In: Many Interviews |
Alert Moderator