Razor tries to learn engine syntax (1)

Source: Internet
Author: User

Recently I wrote about the use of unitofwork mode and repository mode in Nhibernate:

For more information, see:Http://www.cnblogs.com/n-pei/archive/2011/01/11/1933389.html.

The second part will be shared over the weekend.

Today, I would like to share with you the razor syntax. After all, in Asp.net MVC 3, The Asp.net MVC team always recommends that you use the razor engine, in addition, many of its advantages make more and more developers like it.

Razor's blogArticle:

Http://www.cnblogs.com/sl21100/archive/2010/11/17/1879925.html

Http://www.cnblogs.com/facingwaller/archive/2010/12/04/first_time_to_use_razor_in_mvc3.html

Http://www.cnblogs.com/hjf1223/archive/2010/12/16/mvc3-razor.html

I will share with you the information I have seen on the official Asp.net website and the grammar I have learned.

1. Using the @ symbol, you can directly write C # Or VB on the HTML pageCode:

After running:

2. the C # Or VB code on the page is enclosed in braces.

After running:

  

3. Each line of code ends with a semicolon:

After running:

4. Output special characters, double quotation marks, and slashes on the page:

Running effect:

5. Obtain the URL and requesttype of the current page through the request attribute.

Running result:

6. Use if --- else:

In this scenario, we determine whether the current browser will post data to the server. If post is used, we will prompt you to click the post button.

After running:

The following is a complete example:

After you click the submit button, @ totalmessage is the sum of the input text1 and text2.

Razor also has its own type conversion:

There are also annotations in razor. There are two methods -:

  

Good night.

To be continued ......

 

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.