Views and Tag Helper

Learn about the views in MVC, focusing on the Razor view engine, and modifying a home page view in an ASP.NET Core MVC project.

In MVC, the V stands for view. The responsibility of a view is to transform a model into HTML or other formats. Multiple view engines could be used to do this. The default view engine is called Razor, and it uses the @ symbol to indicate server-side code execution. The Razor Pages feature introduced with ASP.NET Core 2.0 uses the same view engine and can use the same Razor syntax.

Rendering the lists of categories

Let’s modify the home page view to render the lists of categories and products:

Step 1: Expand the Views folder, and then expand the Home folder.

Step 2: Open the Index.cshtml file and note the block of C# code wrapped in @{ }. This will execute first and can be used to store data that needs to be passed into a shared layout file, like the title of the web page, as shown in the following code:

Press + to interact
@{
ViewData["Title"] = "Home Page";
}
...