Because there is no specificRazorThe syntax is introduced. Therefore, I have copied these statements from some English blogs. mistakes and omissions are inevitable. Sorry.
ASP. net mvc 3 Preview 1-razor view Engine
ASP. net mvc 3: server-side comments with razor
ASP. net mvc 3: layouts and sections with razor
ASP. net mvc 3 and the @ helper syntax within razor
ASP. net mvc 3: New @ model keyword in razor
ASP. net mvc 3: layouts with razor
ASP. net mvc 3: Razor's @: and <text> syntax
ASP. NET: loop statements in webmatrix and razor
Before you start to explain the syntax, create an entry website in webmatrix to test the syntax.
In ASP. NET, add the server to the pageCodeGenerally, the following mark is used:
<%>
In the razor syntax, the "@" symbol is used to replace the above mark.
Open the default. cshtml file of the Getting Started website and you will see the following code:
@ {<Br/> layout = "~ /_ Sitelayout. cshtml "; <br/> page. Title =" Welcome to my website! "; <Br/>}< br/> <p> <br/> use ASP.. NET web pages. net <SPAN class = 'wp _ keywordlink '> Program </span>. <Br/> </P>
In the Code, under the @ symbol, the code in braces is equivalent to the server code, which is a characteristic of the razor syntax.
A large code block can be placed in braces, but only one line of code, you can directly use the @ symbol, for example, the value of the title attribute of the Page Object displayed on the page, can be in "<. p> "Add the following code before:
</Br> <br/> "<br/>
Click Run to view the result in the browser, as shown in.
In ASP. NET, If You Want To output content in a loop, you must write three tags, Which is troublesome. For example, the following code:
<% For (INT I = 0; I <10; I ++) {%> <br/> <%: @ I %> <br/> <%} %>
In razor syntax, you don't have to worry about it because the code can be mixed together and identified by the @ symbol. For example, the above Code can be written as follows:
@ For (INT I = 0; I <10; I ++) {<br/> @ I <br/> <br/>}< br/>
Add the preceding statement to "@ page. Title" and refresh the page to see "welcome to our website !" The 10 numbers from 0 to 9 are listed.
Compared with the code, we can see that the razor syntax is more beautiful and simple, which is also the biggest characteristic of the razor syntax.