Roadmap › 1. .NET › Step 20
MVC

ASP.NET Core MVC (and Razor Pages)

The MVC pattern, request lifecycle, routing, controllers, model binding and validation, Razor views, layouts, tag helpers, view components, filters, state management, Identity and security.
Quick revision for interview day. Print it or save it as a PDF.

Request lifecycle

Middleware → Routing → Controller (DI) → Authorization filter → Resource filter → Model binding → Validation → Action filter → Action → Action filter → Result filter → View render → Result filter → Response. Exception filters wrap the action/result stages.

Middleware order (MVC)

csharp
app.UseExceptionHandler("/Home/Error"); app.UseHsts();
app.UseHttpsRedirection();
app.UseStaticFiles();   // or MapStaticAssets()
app.UseRouting();
app.UseCors();
app.UseAuthentication();
app.UseAuthorization();
app.UseSession();
app.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");

Passing data

Lifetime
Model (@model)Request — preferred
ViewData / ViewBagRequest
TempDataUntil read (one redirect)
SessionAcross requests

Action results

View · PartialView · ViewComponent · Json · Content · File · Redirect · RedirectToAction · LocalRedirect · NotFound · BadRequest · Unauthorized · Forbid · StatusCode.

Binding attributes

[FromQuery] [FromRoute] [FromForm] [FromBody] [FromHeader] [FromServices] [Bind("A,B")] [BindProperty] (Razor Pages).

Validation attributes

[Required] [StringLength] [MaxLength] [Range] [EmailAddress] [Phone] [Url] [Compare("Password")] [RegularExpression] [Remote] · custom ValidationAttribute · IValidatableObject.

Security checklist

Antiforgery on POST forms · [Authorize] + fallback policy · ownership checks (IDOR) · LocalRedirect for returnUrl · no Html.Raw on user input · HTTPS + HSTS · secure cookies · view models (no over-posting).