C# ASP.NET MVC HtmlHelper用法匯總

來源:互聯網
上載者:User

標籤:

1. @Html.Raw() 方法輸出帶有html標籤的字串:

如: @Html.Raw("<div style=‘color:red‘>Hello World!</div>")

結果:Hello World!

2. @html.ActionLink產生一個<a href=".."></a>標記:

如:@Html.ActionLink(“linkText”、“actionName”、“controlName”,new { id = " 911" },new{ target="_blank"})

結果:<a href = "/controlName/actionName/911">linkText</a>

3. @Url.Action返回一個url

如:@Url.Action(“actionName”、“controlName”,new { id = " 911" })

結果:/controlName/actionName/911

4. @Html.Action載入局部頁面,公用部分的代碼例如:header/footer/menu/logout...

如:@Html.Action("actionName", "controlName")

用法類似@Html.RenderAction

5. @Html.RenderAction

如:@{ Html.RenderAction("_VSPartial", "CMController");}

_VSPartial內容:

@model ActiveTesting<div>    <div>        <div>            <ul>                <li>                    <div>                        <a>Hello World!</a>                    </div>                </li>                @if (Model != null)                {                    <li><a>Li Li</a></li>                }            </ul>        </div>    </div></div>
View Code

原理:根據Controller → Model → View的順序進行執行,然後把結果進行返回

6. @Html.RenderPartial

    將使用者控制項直接嵌入當前頁面

如:@{ Html.RenderPartial("_PatientMRPartial");}

_PatientMRPartial內容:

<div>    <div>        <div>            <h3 class="pull-left">Hello World!</h3>        </div>    </div>    <div>        <div>            <div>                <div>                    <div>                        Tom                    </div>                </div>            </div>        </div>        <div class="row cpnmedication-content-line">            <div>                <div>                    <div class="pull-left">                        Jim                    </div>                </div>            </div>        </div>    </div></div>
View Code

 

C# ASP.NET MVC HtmlHelper用法匯總

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.