Razor is a new extension of Asp.net mvc3 and is also the default view engine.
CodeExpression
The core conversion character of razor is @, which is used to convert from tag to code (this is definitely a micro-controller, so it is concise and cannot be concise)
For example
@{StringName ="Zhangwei";}< H2 >@name </H2>
The razor code block can be automatically converted in the tag and code, such as automatic identification <li> </LI>, and {} can contain a code block.
<Ul> @Foreach(VARInStr) {<li >@a </Li >}</ul>
Solution
I want to output Zhangwei. xxiu, and the code becomes
@{StringName ="Zhangwei";}< H2> @ name. xxiu </H2>
Obviously. xxiu will be treated as an attribute of name, so a bracket is needed to solve the ambiguity.
@{StringName ="Zhangwei";}< H2 >@( name). xxiu </H2>
Use the dual @ number to address the @ content that needs to be output, such as email Weibo.
<P> chxxiu @ gmail.com </P> <a href ="Http://weibo.com/tlaozhang"> @ Zhang Wei-ProgramMember </a>
HTML Encoding
The razor expression uses HTML encoding.
For example
@{StringMassage ="<SCRIPT> alert ('Hello zhangwei') </SCRIPT>";}< H2 >@massage </H2>
If the input is normal, a dialog box will pop up, but the page is actually processed as follows:
<H2> & lt; script & gt; alert (& #39; Hello Zhangwei & #39;) & lt;/script & gt; </H2>
To output a dialog box class, try html. Raw.
<H2> @ html. Raw (massage) </H2>
Comment for trial
@ * Content to be commented *@
Razor Layout
We can see that in the template file _ viewstart. cshtml, there is only one sentence below. layout indicates the path that references the page layout. It refers to a default layout. We can modify this path as needed.
@ {Layout ="~ /Views/shared/_ layout. cshtml";}
In _layout.cs.html, there is the following code. The key is that @ renderbody () is used to hold the location of the main content. This is similar to the space left on the page in the previous template in webfrom.
<Div id ="Body"> @ Rendersection ("Featured", Required:False) <SectionClass="Content-wrapper main-content clear-fix"> @ Renderbody () </section> </div>
It is still very efficient to take notes while reading and Typing Code!