Views

In the Model-View-Controller (MVC) pattern, the view handles the app's data presentation and user interaction. A view is an HTML template with embedded Razor markup. Razor markup is code that interacts with HTML markup to produce a webpage that's sent to the client.

Base View

Theme base view is Views/Layout/Master.cshtml, in this file we are connecting all global styles and scripts. Each layout template should be wrapped with this view.

Content will be rendered in the place of @RenderBody().

Specifying a Layout

Razor views have a Layout property. Individual views specify a layout by setting this property.

@{
    Layout = "~/Views/Layout/Metronic/_Default.cshtml";
}

The layout specified can use a full path (for example, ~/Views/Layout/Good/DefaultDarkSidebar.cshtml) or a partial name (example: _Layout). When a partial name is provided, the Razor view engine searches for the layout file using its standard discovery process. The folder where the handler method (or controller) exists is searched first. This discovery process is identical to the process used to discover partial views.

By default, every layout must call RenderBody. Wherever the call to RenderBody is placed, the contents of the view will be rendered.

All available layout could be found in folder Views/Layout.

Global Partials

Global partials are located inside the Views/Partials Folder. You can use partials in your page views with a partial tag and in the attribute name specify the partial path you want to use.

<partial name='~/Views/Partials/_Drawers.cshtml")' />

Pages

New pages can be added inside a Controllers. For example DashboardsController.cs represents Dashboards folder inside a Views, it has a function which returns View of Views/Dashboards/Index.cshtml.

public IActionResult Index()
{
    return View();
}

You can add a new pages in the same way, add Controller and function inside it which names machs to your Razor view file name in Views/[Controller] folder.

Also you can specify razor view which will be returned by providing a path as a parameter for View function.

public IActionResult Index()
{
    return View("Views/Auth/SignUp.cshtml");
}
Preview Get Help Buy Now