liveBook · Manning

Chapter 19: Creating a website with MVC controllers

What you will learn in chapter 19 of ASP.NET Core in Action, 3e

This chapter introduces MVC controllers as an alternative to Razor Pages, previews their project structure and view rendering, and frames when each approach is preferable.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This chapter introduces MVC controllers as an alternative to Razor Pages, previews their project structure and view rendering, and frames when each approach is preferable.

Key terms: Model-View-Controller (MVC), MVC controllers, Razor Pages, Razor views, server-rendered HTML apps, developer ergonomics, MVC framework, view files, view selection algorithm, Razor view template

19.1 Razor Pages vs. MVC in ASP.NET Core

This section positions Razor Pages, MVC controllers, and API approaches in ASP.NET Core, clarifying the terminology used for HTML and API controllers.

Key terms: Razor Pages, server-side rendered applications, minimal APIs, web API controllers, APIs, ASP.NET Core MVC framework, MVC controllers, HTML, JSON, XML

19.2 Your first MVC web application

This section creates the default MVC web app and explains how its controller actions, Razor views, and conventional routing differ from the equivalent Razor Pages app.

Key terms: ASP.NET Core Web App (Model-View-Controller) template, dotnet new mvc, MVC controllers, Razor views, AddControllersWithViews(), MapControllerRoute(), AddRazorPages(), Program.cs, MVC controller, action method

19.3 Comparing an MVC controller with a Razor Page PageModel

This section compares MVC controllers with Razor Page PageModels, showing that their request handling is largely equivalent apart from controller organization and view rendering.

Key terms: MVC controllers, actions, Razor Pages, PageModel, page handlers, MVC design pattern, dependency injection, model binding, application model, view model

19.4 Selecting a view from an MVC controller

This section explains how MVC controller actions return ViewResults to select, locate, and render Razor views with optional view models.

Key terms: ViewResult, view model, Razor view, Razor engine, action method, Razor View - Empty, Views folder, .cshtml, @page directive, View()

19.5 Choosing between Razor Pages and MVC controllers

This introduction frames Razor Pages as the usual choice for server-rendered applications while clarifying that Razor Pages and MVC controllers are architecturally equivalent MVC approaches with different project organization.

Key terms: Razor Pages, MVC controllers, server-rendered applications, MVC design pattern, project structure, Web Forms, MVC framework

19.5.1 The benefits of Razor Pages

This section explains how Razor Pages differs from Web Forms and why its page-focused organization can be preferable to MVC controllers for many website features.

Key terms: Razor Pages, Web Forms, MVC design pattern, stateful application model, stateless web application, Razor view, .cshtml, .cshtml.cs, PageModel, view model

19.5.2 When to choose MVC controllers over Razor Pages

This section identifies when MVC controllers are preferable to Razor Pages, when neither is the best fit, and how these approaches can coexist in one application.

Key terms: MVC controllers, Razor Pages, HTTP API, web API controllers, partial page updates, partial view results, minimal APIs, JSON API, gRPC, WebSockets

19.6 Summary

This summary recaps how MVC controllers are configured, routed, and used to render views, and when they differ from Razor Pages.

Where this is used later

Concepts explained in this chapter

← Chapter 18: Building forms with Tag Helpers Chapter 20: Creating an HTTP API using web API controllers →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.