A Razor expression puts a C# value into the HTML generated by a Razor view. In a .cshtml file, ordinary HTML supplies the surrounding markup; Razor evaluates an expression such as @Model.Name and inserts its result into the response. A controller action can return a ViewResult and pass a view model whose properties provide those values. section 21.4.2 section 21.5
Put a product in a view
In Views/Home/Index.cshtml, <td>@Model.Name</td> inserts the product name into a table cell. <td>@Model.Price.ToString("c")</td> calls a method to format its price. A view model supplies the properties; declaring its type lets expressions in the view be type-checked. section 21.2.3 section 21.5
Use parentheses when an expression is more complex than a property access or method call. In <td>@Model.Price * 0.2m</td>, Razor treats the asterisk and number as static content: a price of 275.00 produces 275.00 * 0.2m. Write <td>@(Model.Price * 0.2m)</td> to evaluate the multiplication instead; the example produces 55.000. Check the rendered response when code and literal text meet—Razor's boundary may not be the one you intended. section 21.4.3 section 21.4.4
Expressions also work in attribute values. For example, <table data-id="@Model.ProductId"> renders with data-id="1" when that property is 1. Inspect the HTML response to verify the resulting attribute, rather than relying only on how the page looks. section 21.4.4
The @ prefix has other jobs in a view. @if and @switch select content, @foreach repeats it, and @{ ... } defines a code block. A block such as @{ Layout = null; } sets a layout choice; it is not the same as inserting a value with @<expression>. Layouts can use @RenderBody() to insert a view's content. section 21.4.2 section 2.3.3 section 7.1.6
Razor Pages use the same mixture of HTML and expressions. There, @Model.Product?.Name reads through the page model to set an element's content. Behind the scenes, Razor turns page HTML and expressions into calls such as WriteLiteral and Write in a generated C# class. section 23.2.2

