Step by step webmatrix website development 3: One of razor syntax

Source: Internet
Author: User

Because there is no specificRazorThe syntax is introduced. Therefore, I have copied these statements from some English blogs. mistakes and omissions are inevitable. Sorry.

The following is a reference blog post:

ASP. net mvc 3 Preview 1-razor syntax


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.

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.