http://blog.csdn.net/pasic/article/details/7072340
Original address:MVC Razor Syntax (EXT)
Panzhaowen_jacki
| Syntax name |
Razor Syntax |
Web Forms equivalent Syntax |
| code block |
@{int x = 123; string y = "because.";} |
<% int x = 123; string y = |
| expression (default encode) |
<span> @model. Message</span> |
<span><%: Model. Message%></span > |
| expression (not encode) |
<span > @Html. Raw (model. Message) </span |
<span><%= model. Message%></span > |
| Loops that combine text and markup |
@<span> @item. Prop</span>} |
& lt;% foreach (Var item in items) {%> <span><%: Item. Prop%></span |
| code and text blending |
@if (foo) {<text</text >} |
<% if (foo) {%> Plain Text <%}%> |
| Code and text blending |
@if (foo) {@:P lain Text is @bar} |
Ditto |
| Email address |
Hi [email protected] |
Razor know the basic message format. Intelligent identification. |
| display expression |
<span>[email protected "(Isbnnumber) Span style= "color: #0000ff;" ></span> |
in parentheses you can do something simple. Extended Show me the result of the @ (20*pageindex) output Operation |
output @ symbol |
Span style= "Font-family:consolas;" ><span>in Razor The @ @foo to display the value of Foo</span< Span style= "color: #0000ff;" >> |
|
| Server-side comments |
This is a server side multiline comment *@ |
<%--This is a server side multiline comment--%> |
| Call a method |
@ (myclass.mymethod<atype> ()) |
Use parentheses to express what is. |
| Create a razor delegate |
@{func<dynamic, Span style= "color: #0000ff;" >object> B = @<strong > @item </strong >;} @ B ("Bold this") |
More information view this blog post . |
| Mixed expressions and text |
@title. @name. |
<%: Title%>. <%: Name%>. |
Hope to help you.
Add a method that displays a JSON object in the view's scripting script
Requirement: Var data=[{id:1,title= "title 1},{id:2,title=" Title 2 "}]
implementation: VAR [email protected] (@Newtonsoft. Json.JavaScriptConvert.SerializeObject (Model))
Use Json.NET to convert and then raw output can be