ASP.NET Core MVC Interview Question #10

What is a Razor view in ASP.NET Core MVC?

MVC Fundamentals, Controllers, Views & Routing Junior Beginner

Quick Interview Answer

A Razor view is a .cshtml file that combines HTML with Razor syntax to generate server-rendered output. Views receive data from controllers, commonly through strongly typed view models, and use Razor expressions, directives, tag helpers, partials, layouts, and sections to build the final HTML.

Detailed Explanation

A Razor view is a .cshtml file that combines HTML with Razor syntax to generate server-rendered output. Views receive data from controllers, commonly through strongly typed view models, and use Razor expressions, directives, tag helpers, partials, layouts, and sections to build the final HTML.

Views should focus on presentation. Database access and substantial business logic should not be placed directly inside Razor views.

Code Example

@model ProductViewModel

<h1>@Model.Name</h1>
<p>Price: @Model.Price</p>