Razor view basic syntax in MVC (1)

Source: Internet
Author: User

Razor front, must be with the front of the gap, that is, the space, after the need to be coherent, otherwise add parentheses

1, when outputting a single variable in the page, simply precede the C # statement with the @ symbol.

For example

1 <p>2     present moment: @DateTime. Now3 </p>

2, if you want to output a paragraph containing a blank word or word operation results, you must add a parenthesis before and after

1 <p>2     member name: @ (viewbag.isenabled?" ) enabled " " Deactivate " )3 </p>

3, to execute multiple lines of C # code on a page, you must add a curly brace (but conform to the C # code specification and each line plus; number).

<p>    @{            int i=2;             int 4 ;        } </p>

4, in order to insert HTML or other text content in the multiline C#razor syntax, you must add "@:" at the top of each line, plus the "@:" symbol in this line of code, plus other razor variables

@{        var name=" Zhang San ";        @: Hello, I'm @name}

It should be considered as a C # statement sentence to enter plain text directly in razor, want to enter a lot of text, if all add @: It is inconvenient, you can

1 @{2 @* just add the HTML tag. *@3     <span> Stephensteffen going to leave </span>  4 }

5, razor in the note can be used @*code*@;

6, to output the @ symbol,

 1 @@ 你好

Output

@ Hello

Razor view basic syntax in MVC (1)

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.