Professional Documents
Culture Documents
Advance Web Application Development: Instructor: Dr. Syed Ali Raza Department of Computer Science GC University Lahore
Advance Web Application Development: Instructor: Dr. Syed Ali Raza Department of Computer Science GC University Lahore
Development
Instructor: Dr. Syed Ali Raza
Department of Computer Science
GC University Lahore
Lecture 7
Introduction to Razor Pages
Give someone a program, you frustrate them for a day;
teach them how to program, you frustrate them for a
lifetime.
— David Leinweber
View Engine
• A view engine is responsible for rendering the view into html form to
the browser.
• ASP.NET MVC includes two different view engines
• Web Forms View Engine (MVC1 and MVC2)
• Razor View Engine (MVC 3 and forward)
• Razor View Engine
• Simplified syntax but not a new language.
• A code focused templating syntax optimized around HTML generation
• Works with any text editor
• IntelliSense with Visual Studio 2010 and higher
Razor View Engine
• Code Blocks
• In addition to code expressions, Razor also supports code blocks within a view.
• Inside a code block, each complete code statement must end with a semicolon.
• Inline expressions don't end with a semicolon.
• Consider the lines
@{ var items = new string[] { “Model", “View", “Controller" }; }
@foreach (var item in items)
{
<li>The item name is @item.</li>
}
• This block of code iterates over an array and displays a list item element for each
item in the array.
• The foreach statement automatically transitions to markup with the open tag.
• Razor understands the structure of HTML markup, it also transitions automatically
back to code when the tag is closed.
• Blocks of code require curly braces to delimit the block of code in addition to an @
sign. It is commonly used for variable declarations, to perform calculations etc.
More fun with @ character