Introduction - Razor View engine is a markup syntax that helps us to write down HTML and server-side code in web applications using C# or VB.NET. it's server-side language however it's not the least bit a programing language.
Razor is a templating engine and ASP.NET MVC has implemented a view engine that allows us to use Razor inside an MVC application to supply HTML. However, Razor doesn't have any ties with ASP.NET MVC. Now,
- Easy to Learn, Razor is simple to find out,
- we are able to also use our existing HTML skills.
- It is Compact, Expressive, and Fluid. Razor helps us to segregate the coding and supply us with a quick and fluid coding workflow.
- The parser (available with Razor) is wise enough. it's also able to decide at run time what's a code element and what's a content element.
- webformorm view engine requires the code block to be closed properly otherwise it throws a runtime exception.
- A webform View engine doesn't prevent Cross-Site Scripting (XSS) attacks.
- The Razor View Engine could be a bit slower than the ASPX View Engine.
- WebForm view engine doesn't support Test Driven Development (TDD) because it depends on the System. Web. UI. Page class to form the testing complex.
- Razor syntax isn't working in Dream Viewer editor.
- Sometimes it's not engaged on the run time processing
The syntax for the Razor View Engine is given below-
- It must be always enclosed in @
- Semicolon â€œ;â€ must be wont to ending statements
- Files have .cshtml extension.
- Variables are declared with var keyword
- Inline expressions (variables and functions) start with @
- C# code is case sensitive
Razor provides a brand new view engine with streamlined code for focused templating. Razor's syntax is extremely compact and improves the readability of the markup and code. By default, ASPX (web forms) and Razor View Engine supported by this MVC