Razor syntax (5)

Source: Internet
Author: User

Convention: ClientCodeIt is called the C domain, and the server code is called the S domain.

0. Basic Principles
The default razor template is a CDomain (same as PHP and aspx)
Any CDomain can be embedded with the S domain
The S domain in the row cannot be embedded with the C domain, and the S domain in multiple rows can be embedded with any C domain
@ Symbol is the key symbol. Use @ to switch from the C domain to the S domain.
Use tags to switch from S domain to multi-row C domain, and use @: to switch from S domain to intra-Row C domain

1. Several Forms of intra-row s domain
@ Variable for example: @ user. name. The variable or attribute is automatically changed back to the C field after the end of the variable or attribute. In case of ambiguity in the end judgment, enclose the following brackets:
@ (Expression) for example: @ (I + 1) or @ (user. Name)
@ Method call example: @ html. Textbox ("username"). tostring ()

2. Several Forms of multi-row s domain
@ {Code block}
@ If (condition) {code block}
@ Switch (condition) {branch matching code block}
@ For (Loop Control) {code block}
@ Foreach (Loop Control) {code block}
@ While (Loop Control) {code block}
@ Do {code block} while (loop control );

3. Form of intra-row CDomain
@: Line text. The line feed is automatically changed back to the s field.

4. Several Forms of multi-row cdomains
For example, <div> multiline text </div>
Any self-closed tag, for example,
Use a pseudo label for plain text <text> For example: <text> multiple lines of text, labels on both sides are not output </text>

5. Conflict Resolution
Email can be automatically identified and output for example: hello@hotmail.com will be correctly output in text form
For example, the hello@User.Name will be misjudged as an email address, should be resolved in parentheses, namely: Hello @ (user. Name)
If it is not an email address, @ is used to escape the output of a single @

6. preset Directive
@ Model specifies the model used by the view.
@ Section indicates the definition of starting a section.
@ Helper defines an htmlhelper Extension

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.