MVC Razor Syntax (GO)

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.