|
|
MvcCms Razor Notes
Since Razor is a new thing and there might be some confusion of the order of precedence between the two view engines in MvcCms we will keep notes here on how Razor is panning out in MvcCms.
For now here is the syntax for the RTM from haacked.
http://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx
| Syntax/Sample | Razor | Web Forms Equivalent (or remarks) |
|---|---|---|
| Code Block | @{ int x = 123; string y = "because."; } |
<% int x = 123; string y = "because."; %> |
| Expression (Html Encoded) |
<span>@model.Message</span> |
<span><%: model.Message %></span> |
| Expression (Unencoded) |
<span> |
<span><%= model.Message %></span> |
| Combining Text and markup |
@foreach(var item in items) { <span>@item.Prop</span> } |
<% foreach(var item in items) { %> <span><%: item.Prop %></span> <% } %> |
| Mixing code and Plain text |
@if (foo) { <text>Plain Text</text> } |
<% if (foo) { %> Plain Text <% } %> |
| Mixing code and plain text (alternate) |
@if (foo) { @:Plain Text is @bar } |
Same as above |
| Email Addresses |
Hi philha@example.com |
Razor recognizes basic email format and is smart enough not to treat the @ as a code delimiter |
| Explicit Expression |
<span>ISBN@(isbnNumber)</span> |
In this case, we need to be explicit about the expression by using parentheses. |
| Escaping the @ sign |
<span>In Razor, you use the @@foo to display the value of foo</span> |
@@ renders a single @ in the response. |
| Server side Comment |
@* This is a server side multiline comment *@ |
<%-- This is a server side multiline comment --%> |
| Mixing expressions and text |
Hello @title. @name. |
Hello <%: title %>. <%: name %>. |
Edit Comment
Please wait...

Reply To Comment
Please wait...


You must be Loged On to make a comment.