ASP.NET Core MVC Interview Question #12

What is a strongly typed view?

MVC Fundamentals, Controllers, Views & Routing Junior Beginner

Quick Interview Answer

A strongly typed view declares its model type with the @model directive. Razor then exposes that object through the Model property with compile-time type information and IntelliSense.

Detailed Explanation

A strongly typed view declares its model type with the @model directive. Razor then exposes that object through the Model property with compile-time type information and IntelliSense.

Strongly typed view models are generally safer and easier to maintain than passing many unrelated values through ViewBag or ViewData. They also allow validation metadata and editor/display helpers to work with a defined model.

Code Example

@model ProductDetailsViewModel

<h2>@Model.Name</h2>
<span>@Model.Price.ToString("C")</span>