Razor Engine:-
- Razor engine represents a view engine that is used to render a Web page that uses the ASP.NET Razor syntax
- It is clean, lightweight and simple view engine. It is introduced with ASP.NET MVC 3 and is the default view engine moving forward
- Razor provides a streamlined syntax for expressing views that minimizes the amount of syntax and extra characters
Language:-
- Razor syntax is supported with both C# and visual basic.
- C# syntax are used in view files with file extension .cshtml
- Visual basic used in view files with file extension .vbhtml
Based upon the file extension, corresponding Razor parser is used to compile the code language.
Code expression used in Razor:-
@if (price > 30) { @foreach(var item in Model) {
}- @item.ToString()
}
Code expression used in ASPX Syntax:-
<% if(price>30) { %> <% foreach(var item in Model) { %>
<% } %>- <%: item.ToString() %>
<% } %>