Below is a complete, well-structured article covering Razor View, Razor Layout, Razor View Imports, and Razor Pages in ASP.NET Core — including definitions, purposes, step-by-step creation, and examples.
You can directly use this as a blog article.
ASP.NET Core provides a powerful UI rendering engine called Razor, which helps developers build clean, dynamic, and fast web applications using C# and HTML together. This article explains four important Razor concepts:
Razor View
Razor Layout
Razor View Imports
Razor Pages
Each concept is explained with purpose, usage, and practical examples.
1. Razor View
What Is a Razor View?
A Razor View is a .cshtml file that contains HTML markup mixed with C# code using Razor syntax (@).
It is used for rendering data to the browser.
Example Razor View syntax:
<h1>Hello @Model.Name</h1>
Purpose of Razor View
To build the user interface of an MVC application.
To bind data using a model sent from a controller.
To reduce the need for writing raw HTML and server-side code separately.
How to Create a Razor View in ASP.NET Core?
Step 1: Create MVC Controller
public class HomeController : Controller
{
public IActionResult Index()
{
ViewBag.Message = "Welcome to ASP.NET Core Razor View!";
return View();
}
}
Step 2: Create View File
Go to:Views → Home → Index.cshtml
Index.cshtml Example
@{
ViewData["Title"] = "Home Page";
}
<h2>@ViewBag.Message</h2>
<p>This is a sample Razor View.</p>
2. Razor Layout
What Is a Layout in ASP.NET Core?
A Layout is a master template file that contains common design parts such as:
Header
Navigation menu
Footer
Common scripts & CSS
It behaves like a master page (in ASP.NET Web Forms).
Default layout file:Views/Shared/_Layout.cshtml
Purpose of Razor Layout
Avoids repeating the same HTML code on every page.
Provides a consistent, uniform layout across the site.
Example: _Layout.cshtml
<!DOCTYPE html>
<html>
<head>
<title>@ViewData["Title"]</title>
<link rel="stylesheet" href="~/css/site.css" />
</head>
<body>
<header>
<h1>My Website</h1>
<nav>
<a href="/">Home</a> |
<a href="/About">About</a>
</nav>
</header>
<main>
@RenderBody() <!-- Page content comes here -->
</main>
<footer>
<p>© 2025 MyApp</p>
</footer>
</body>
</html>
Using Layout in View
Inside Index.cshtml:
@{
Layout = "_Layout";
}
Now your page automatically fits into the layout.
3. Razor View Imports
What Is _ViewImports.cshtml?
_ViewImports.cshtml is used to import common namespaces, tag helpers, models, etc., for all views in a folder.

Join the conversation! Your thoughts help the community grow.