Master Page does not appear in the list when I try to associate it to a view

Asked

Viewed 622 times

3

I am using Microsoft Visual Studio 2013 and created a C# ASP.NET MVC 4 project.

I created a Master Page in the directory of Views, calling for Modelo.master. Then I created a Controller in the directory Controllers, and again a View that displayed the output of the Controller.

However, on the creation screen of Views where the program asks to select a Master Page or layout to use as the base of the page I cannot view the Master Page that I created. The archive Modelo.master not even on the list.

What could be?

1 answer

3


At Razor, the model of Master Page is not used. What exists are files from Layout, used by View to build.

Unlike Master Pages, where content sections were specified using a set of tags of their own, Razor uses pure HTML, processing notations and returning more HTML. The approach is simpler and less error-prone on the server part.

Normally the Main view layout file (i.e., the one that opens in a computer browser) is inside Views\Shared by the name of _Layout.cshtml, but nothing prevents you from modifying this name. In this directory should be placed other Layout files common to the system. Layouts that are specific to certain Views belonging to a Controller can be in the specific directory of these Views.

The Wizard that you executed only generates a View with the following statement, which is fully optional:

@{
    Layout = "~/Views/Caminho/Da/Minha/View/_Layout.cshtml";
}

This statement is also found in the special View _ViewStart.cshtml, which starts a Default Layout if no Layout is specified:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.