Views are the presentation layer of an ASP.NET Core MVC application.
They are responsible for displaying HTML content to the user.
Most MVC views are written using Razor syntax and stored as .cshtml files.
A view displays content such as headings, text, forms, tables, images, and buttons. It can also display data passed from a controller.
Views are usually stored inside the Views folder. They are commonly grouped by controller name.
Views/
Home/
Index.cshtml
About.cshtml
For example, the Index() action in HomeController usually looks for:
Views/Home/Index.cshtml
@{
ViewData["Title"] = "Home Page";
}
Welcome to ASP.NET Core
This is my first Razor view.
Razor is a syntax that allows you to mix HTML with C# code inside a view.
The @ symbol is used to switch into C#.
@ViewData["Title"] reads a value@Model.Name displays a model property@foreach loops through dataA controller can send data to a view, and the view can show it to the user.
public IActionResult Welcome()
{
ViewBag.Message = "Hello from the controller";
return View();
}
Then in the view:
@ViewBag.Message
Most views are displayed inside a shared layout. A layout provides the common page structure, such as the header, menu, and footer. This avoids repeating the same HTML on every page.
Views are where users see the results of your application. Once you understand Razor syntax and the Views folder structure, you can start building dynamic user interfaces more confidently.