liveBook · Manning

Controller

As explained in .NET in Action, Second Edition

An MVC controller is the component that receives requests or user input and coordinates the model and view used to produce a response.

An MVC controller receives user input or an HTTP request, coordinates the model and view, and produces the response. Its actions handle distinct requests and return results such as HTML, JSON, images, or status codes. section 3.2.1 section 3.1.2

In ASP.NET Core, controllers fit into several related request-handling styles:

  • A conventional MVC controller is a class whose action methods handle unique requests and select the model and view. section 3.1.2
  • A Razor page combines view and controller responsibilities for simple page interactions, while keeping application data and logic separate. section 3.2.1
  • Minimal APIs create actions directly with methods such as app.MapGet, avoiding an explicit controller class. section 3.1.2
  • Controllers can perform CRUD operations through Entity Framework Core, while asynchronous techniques help avoid blocking application threads during database requests. section 5.6

Selecting an HTTP result

A request for ASCII art can return content when the requested font exists and a 404 Not Found result when it does not. The conditional minimal-API endpoint demonstrates the same action-result decision without a controller class. section 3.1.2

Diagram of the MVC pattern in which the user request goes to the controller, which can update the model and get the latest view to send in the response

Follow the request-to-controller-to-model/view flow, including the resulting response. section 3.2.1

How .NET in Action, Second Edition covers it

How deep it goes
Defines responsibilities and runtime flow, then contrasts controller classes with Razor pages and minimal APIs without detailing controller implementation.
Examples
Uses an MVC request-flow diagram, Razor Index.cshtml, an invalid-font 404 endpoint, and controller-based CRUD with SwaggerUI testing.
What it assumes
Assumes basic HTTP requests and responses, while establishing MVC terminology and separating application data and logic from views.
What you can do after
Apply it via ASP.NET Core by distinguishing controller actions, Razor page handlers, and minimal-API endpoints.
How it connects
Connects controllers to MVC, models, views, actions, Razor pages, minimal APIs, ActionResult, Entity Framework Core, and CRUD operations.

Also explained in

Compare how 8 books explain controller →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of .NET in Action, Second Edition. The section links point to the parts of the book it draws on.