What is a strongly typed view in ASP.NET MVC?
Quick Answer
A strongly typed view declares the model type it expects with @model at the top. Inside, Model is that type, so you get IntelliSense, compile-time checking and strongly typed HTML/tag helpers like @Html.TextBoxFor(m => m.Name) or <input asp-for="Name">.
A strongly typed view is one that names its model with @model at the top. That makes Model a real type instead of dynamic, so I get IntelliSense and compile-time checking, and I can use the For helpers or asp-for tag helper — asp-for="Name" — which generate the right name and id attributes so binding and validation just work. I always pass a view model that's specific to the view rather than the EF entity, so the view only sees the fields it should and I'm not exposed to over-posting.
Without a declared model, a view uses ViewData/ViewBag and everything is dynamic or an object cast — typos become runtime errors. With @model MyApp.ViewModels.CustomerEditViewModel:
Model.Nameis checked at compile time (views compile in Core).- Helpers bound with a lambda —
TextBoxFor,LabelFor,ValidationMessageFor, or theasp-fortag helper — generate the correctname/idattributes so model binding works on POST. - Validation attributes on the model surface automatically next to the field.
Best practice is a dedicated view model per view — not the EF entity — containing exactly the fields that view needs, plus display/validation attributes. This avoids over-posting and keeps the domain model clean.
@model CustomerEditViewModel
<form asp-action="Edit" method="post">
<label asp-for="Name"></label>
<input asp-for="Name" class="form-control" />
<span asp-validation-for="Name" class="text-danger"></span>
<button type="submit">Save</button>
</form>
Practise the whole thread the way an interviewer walks it — each question builds on the last.
- What is ASP.NET MVC?
- Explain the ASP.NET MVC request life cycle.
- What is routing in ASP.NET MVC?
- What is ActionResult in ASP.NET MVC?
- What is the difference between ViewBag, ViewData and TempData?
- What is a strongly typed view in ASP.NET MVC?You are here
- How does model validation work in ASP.NET MVC?