liveBook · Manning

Razor expression

A Razor expression is an inline construct that evaluates an embedded C# expression and inserts its result into generated output.

How 2 Manning books explain it

Pro ASP.NET Core 7, Tenth Edition

A Razor expression is an embedded expression in a Razor view that Razor evaluates to produce content in the generated response.

How it is used
Inserts evaluated C# values into HTML responses generated by Razor views and Razor Pages.
How deep it goes
Works through property access, method calls, arithmetic boundaries, and attributes, then identifies generated C# calls without tracing compilation in detail.
Examples
Uses a product table, currency formatting, contrasting tax calculations, a rendered data-id attribute, and page-model property access.
What you can do after
Build it from scratch in a .cshtml view to insert model values and avoid mistaking arithmetic for literal content.

Read how Pro ASP.NET Core 7, Tenth Edition explains razor expression →

ASP.NET Core in Action, 3e

A Razor expression is an inline Razor construct that evaluates a C# expression and writes its result to the generated HTML output.

How it is used
Renders C# values from Razor Pages models or ViewData directly into dynamic HTML.
How deep it goes
Defines @, @(), and @@ syntax, contrasts expressions with @{} code blocks, and extends into loops and conditionals.
Examples
Uses copyright text, arithmetic output, and a to-do list rendered conditionally from model data.
What you can do after
Apply it via Razor syntax to render model values and generate data-dependent HTML without manually building response strings.

Read how ASP.NET Core in Action, 3e explains razor expression →

Related concepts

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.