Razor new view engine asp.net
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Razor new view engine asp.net

on

  • 3,917 views

In this presentation give a general overview of razor- new view engine in asp.net. This presentation is presented at the seminar titled "Microsoft Talkz" in AIUB organized by Microsoft.

In this presentation give a general overview of razor- new view engine in asp.net. This presentation is presented at the seminar titled "Microsoft Talkz" in AIUB organized by Microsoft.

Statistics

Views

Total Views
3,917
Views on SlideShare
3,912
Embed Views
5

Actions

Likes
1
Downloads
77
Comments
0

1 Embed 5

http://actiesite.hr.nl 5

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Razor new view engine asp.net Presentation Transcript

  • 1. ‘ Razor’ new ASP.NET View Engine Ahsan Murshed Software Engineer
  • 2. Introduction
    • Microsoft is developing a "view engine" for its ASP.Net Web development platform
    • Main goal: optimized around HTML generation via a code-focused templating approach
    • “ Razor” uses a new file suffix “cshtml” or “vbhtml”, where the prefix is the language used in the file.
  • 3. Razor-view engine
    • The view engine, a pluggable module that implements different template syntax options
    • It provides full HTML, JavaScript, and C#/VB code Intellisense within Razor-based files
    • Razor syntax is designed around one primary goal: Make code and markup flow together
  • 4. Sample
    • Old style ASPX
    • <ul>
    • <% foreach(var p in Model.Products) { %>
    • <li><%= p.Name %> ($<%= p.Price %>)</li>
    • <% } %>
    • </ul>
    • Now let’s, removing all of the extra ASPX control characters
    • New style ASPX with ‘Razor’
    • <ul>
    • foreach(var p in Model.Products) {
    • <li>p.Name ($p.Price)</li>
    • }
    • </ul>
  • 5. Sample
    • C#
    • <ul>
    • @foreach(var p in Model.Products) {
    • <li>@p.Name ($@p.Price)</li>
    • }
    • </ul>
    • The &quot;@&quot; character is the magic character in Razor
    • One character, not 5 “<%=%>”, and we let the parser figure out the rest.
  • 6. Design goals
    • Compact, Expressive, and Fluid
    • Easy to Learn
    • Is not a new language
    • Works with any Text Editor
    • Has great Intellisense
    • Unit Testable
  • 7. Why?
    • Razor enables you to start with static HTML (or any textual content) and then make it dynamic by adding server code to it. 
    • One of the core design goals behind Razor is to make this coding process fluid, and to enable you to quickly integrate server code into your HTML markup with a minimum of keystrokes.
  • 8. Comparison
    • Using ASP.NET’s existing .ASPX markup syntax, we might write it using <%= %> blocks to indicate “code nuggets” within our HTML markup like so:
  • 9. Comparison
    • Start of a code block with Razor using a @ character.  Unlike <% %> code nuggets, Razor does not require you to explicitly close the code-block:
  • 10. Basic syntax
    • If-Blocks Statements
    • Multi-line Statements
  • 11. Basic syntax
    • Multi-Token Statements
    • The @( ) syntax enables a code block to have multiple tokens. For example, we could re-write the above code to concatenate a string and the number together within a @( code ) block.
  • 12. Basic syntax
    • Razor’s language parser is clever enough in most cases to infer whether a @ character within a template is being used for code or static content
    • Razor examines the content on the right-hand side of any @ character and attempts to determine whether it is code or whether it is just static content.
  • 13. Basic syntax
    • Identifying Nested Content
    • When nesting HTML content within an if/else, foreach or other block statement, you should look to wrap the inner content within an HTML or XML element
  • 14. VS support
    • One can get a rich code editing experience within Visual Studio 2010.  Which will provide full HTML, JavaScript and C#/VB code intellisense within Razor based files
  • 15. References
    • http://weblogs.asp.net/scottgu/archive/2010/07/02/introducing-razor.aspx
    • http://www.asp.net/webmatrix/tutorials/2-introduction-to-asp-net-web-programming-using-the-razor-syntax
    • http://weblogs.asp.net/fredriknormen/archive/2010/07/06/razor-the-new-asp-net-view-engine.aspx
    • http://blog.andrewnurse.net/CategoryView,category,Razor.aspx
  • 16. Contract
    • Email: [email_address]
    • Blog: http:// aspboss.blogspot.com
    • Site: http://www.dotnetboss.com