Razor expression
A Razor expression is an inline construct that evaluates an embedded C# expression and inserts its result into generated output.
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 →
What to know first
- HTMLHTML is the standard markup language for structuring content and elements in documents on the web.
Related concepts
- attributeuses · An attribute is a named property or piece of information associated with an entity, object, or structured data item.
- HTMLproduces · HTML is the standard markup language for structuring content and elements in documents on the web.
- viewused by · A view is a presentation component or template that renders application data into a user-interface element or client response.
- view modeluses · A view model is a data structure that supplies a user-interface view with information formatted for display.
- data attributeuses · An HTML data attribute is a custom attribute whose name begins with data- and whose value stores application-specific information on an element.
- methoduses · A method is a callable function or operation associated with a type, class, or object and invoked through that association.
Questions about razor expression
What is razor expression?
A Razor expression is an inline construct that evaluates an embedded C# expression and inserts its result into generated output.
Which Manning books explain razor expression?
Pro ASP.NET Core 7, Tenth Edition and ASP.NET Core in Action, 3e.
What should I know before learning razor expression?
Manning books that teach razor expression usually introduce HTML first.
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.

