@Html.Raw()用法和Html.ActionLink的用法總結


@Html.Raw() 方法輸出帶有html標簽的字符串,

如:@Html.Raw("<div style='color:red'>輸出字符串</div>")

結果:輸出字符串 (紅色字體的字符串)

 使用Razor中的Html.Raw(推薦使用這種方式)

 
Html.ActionLink的用法總結
1、Html.ActionLink("linkText","actionName")
第一個參數:要顯示的文本,第二個參數:視圖名
例如:<%=Html.ActionLink("跳轉到About頁面", "About");%> → <a href="/Home/About">跳轉到About頁面</a>
 
2、Html.ActionLink("linkText","actionName","controlName")
第一個參數:要顯示的文本,第二個參數:視圖名, 第三個參數:控制器名
例如:<%= Html.ActionLink("跳轉到別的controler中", "Index", "Home");%> →<a href="/ Home/Index">跳轉到別的controler中</a>
 
3、
Html.ActionLink("linkText","actionName",routeValues)
第一個參數:要顯示的文本,第二個參數:視圖名, 第三個參數:url中的參數
例如:<%=Html.ActionLink("跳轉到About頁面", "About", new { id = "1", name = "x" }) %> → <a href="/Home/About/1?name=x">跳轉到About頁面</a>
 
4、 
Html.ActionLink("linkText","actionName",routeValues,htmlAttributes)
第一個參數:要顯示的文本,第二個參數:視圖名, 第三個參數:url中的參數,第四個參數:設置標簽屬性
例如:<%=Html.ActionLink("跳轉到About頁面", "About", new { id = "1", name = "x" }, new { disabled = "disabled",@class = "about"})%>  →
 <a class="about" disabled="disabled" href="/Home/About/1?name=x">跳轉到About頁面</a>
 
注意:設置標簽的class屬性時,應在class前加上@,因為class是關鍵字。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM