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