ASP.NET MVC3細嚼慢咽---(3)Razor視圖文法

來源:互聯網
上載者:User

標籤:

  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視圖文法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.