標籤:
MVC3.0中新增加了Razor視圖,Razor視圖的文法以@符號為核心,貌似在這個時代離不開@了,微博,郵箱都用這個。
1.輸出變數和文本 [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標籤編碼 預設情況下是對HTML標籤編碼的。 使用HTML.RAW對HTML標籤不進行編碼 [html] @{ string str = "Hello <br/>Word"; @str @Html.Raw(str) } @{ string str = "Hello <br/>Word"; @str @Html.Raw(str) } 3.注釋 使用@* 注釋內容 *@符號進行注釋 [html] @* //返回方法傳回值 *@ @*//返回方法傳回值*@ 4.單行輸出 使用@:進行單行輸出, 也可以使用 text標記進行單行輸出 [html] @{ @: Hello @: world } <text> Hello world </text> @{ @: Hello @: world } <text> Hello world </text> [email protected]前無空格輸出變數 如果@前無空格輸出變數,可以使用@()進行輸出 [html] <p>[email protected](DateTime.Now)</p> <p>[email protected](DateTime.Now)</p> 6.在頁面中輸出@符號 如果想在頁面中輸出@符號,可用兩個@符號來代替 [html] <p>[email protected]@@(DateTime.Now)</p> <p>[email protected]@@(DateTime.Now)</p>
ASP.NET MVC3細嚼慢咽---(3)Razor視圖文法