21 Using controllers with views, part I

This chapter covers

  • Using controllers with views to programmatically generate HTML content
  • Using the Razor view syntax to mix code and markup
  • Selecting a view in an action method
  • Using view models to pass data from an action to a view

In this chapter, I introduce the Razor view engine, which is responsible for generating HTML responses that can be displayed directly to the user (as opposed to the JSON and XML responses, which are typically consumed by other applications). Views are files that contain C# expressions and HTML fragments that are processed by the view engine to generate HTML responses. I show how views work, explain how they are used in action methods, and describe the different types of ...

Get Pro ASP.NET Core 7, Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.