Razor Syntax
Last updated
Was this helpful?
Last updated
Was this helpful?
Razor is a markup syntax for embedding .NET-based code into webpages.
It consists of Razor markup, C# and HTML.
Razor files have the .cshtml extension.
Razor syntax is used in ASP.NET Core MVC views.
Razor syntax is used to create dynamic content in views, ie. server-side code in views.
Note: The source code for this practical can be found .
The default Razor language is HTML.
HTML markup in .cshtml Razor files is rendered by the server unchanged.
For example:
To escape an @ symbol in Razor markup, use a second @ symbol:
Implicit expressions start with @ followed by C# code.
Examples:
Avoid spaces within implicit expressions (except for the await keyword).
Tag Helpers resemble HTML tags and encapsulate server-side logic.
Example using the LabelTagHelper: