MVC3.0 in the new Razor view, razor view of the syntax with the @ symbol as the core, seemingly in this era inseparable from the @, Weibo, mailboxes are used this.
1. Output variables and text [html] @DateTime. Now @DateTime. now[html] View [email protected] ( int i = 0; I < 5; i++) { <p>@i</p> } @for (int i = 0; i < 5; i++) { < ;p >@i</p>} 2.html tag Encoding HTML tags are encoded by default. use Html.raw to encode HTML tags [html] @{ string str = "Hello <br/>word"; @str @Html. Raw (str) } @{ String str = "Hello <br/>word"; @str @Html. Raw (str) } 3. Comments using @* Comment Content *@ notation [html] @* //return method return value *@ @*//return method return value *@ 4. Single-line output Use @: For single-line output or single-line output with text tags [html] @{ @: Hello @: World } <text> Hello World </text> @{ @: hello @: World } <text> hello world </text> [email Protected] No space output variable if @ before no space output variable, you can use @ () to output &NBSP;[HTML]&NBSP;<P>[EMAIL&NBSP;PROTECTED] (DateTime.Now) </p> <p>[email protected] (datetime.now) </p> 6. Output @ symbol in page If you want to output the @ symbol in the page, use two @ symbols instead of [html] <p>[email protected]@@ (DateTime.Now) </p> <p>[email protected]@@ (DateTime.Now) </p>
ASP MVC3 Chewing---(3) Razor view syntax