3 Working with Razor Pages

 

This chapter covers

  • Generating HTML with Razor templates
  • Learning the Razor syntax
  • Working with layouts, partials and Tag Helpers
  • Understanding the PageModel as a controller and view model
  • Working with handler methods and IActionResult

At this point, you should have a good understanding of the working parts of a Razor Pages application - how to create one, the role of the generated files, and how to configure the application’s behavior through the request pipeline. Now you are ready to take a deep dive into working with the principal actor within a Razor Pages application - the Razor page itself.

As you work through the chapter, you will learn how to use Razor syntax to generate dynamic HTML and coordinate layouts and partial files to reduce your repetition of code and improve reuse. You have already had a brief introduction to layouts and partials, but to remind you, layouts act as a kind of master template for multiple pages, and partial files consist of snippets of UI that can be plugged into a host page or layout.

3.1 Working with Razor syntax

 
 
 

3.1.1 Directives and code blocks

 
 

3.1.2 Rendering HTML with expressions

 
 
 

3.1.3 Control blocks in Razor

 
 
 

3.1.4 Rendering literal strings

 
 

3.1.5 Rendering literal HTML

 

3.2 Layout Pages

 

3.2.1 Assigning the Layout

 
 

3.2.2 Injecting optional content with sections

 
 
 

3.3 Reusable HTML with Partial Views, Tag Helpers and View Components

 
 
 

3.3.1 Partial Views

 

3.3.2 Tag Helpers

 
 

3.3.3 View Components

 
 
 

3.4 The PageModel

 
 
 

3.4.1 Passing data to pages

 
 
 
 

3.4.2 The PageModel as a view model

 
 
 

3.4.3 The PageModel as a controller

 

3.5 Summary

 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest