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>@Html.Raw(model.Message) </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 --%> |
Calling generic method | @(MyClass.MyMethod<AType>()) | Use parentheses to be explicit about what the expression is. |
Creating a Razor Delegate | @{ Func<dynamic, object> b = @<strong>@item</strong>; } @b("Bold this") | Generates a Func<T, HelperResult> that you can call from within Razor. See this blog post for more details. |
Mixing expressions and text | Hello @title. @name. | Hello <%: title %>. <%: name %>. |
Sunday, 17 June 2012
Razor Quick Reference
Subscribe to:
Post Comments (Atom)
What should you required to learn machine learning
To learn machine learning, you will need to acquire a combination of technical skills and domain knowledge. Here are some of the things yo...
-
Introduction This article is aimed at people who are new to the world of Raspberry Pi [Like me]. It gives an idea about what Raspberry P...
-
A simple set of question framings was defined by Kipling in his immortal poem: I have six faithful serving men They taught me all ...
-
In this article we explain how to attain the goal of applying the SAP OpenUI5 user interface library to create line-of-business applicatio...
No comments:
Post a Comment