C # ASP. NET MVC HtmlHelper Usage Summary

Source: Internet
Author: User

1. @Html the. Raw () method to output a string with an Html tag:

such as: @Html. Raw ("<div style= ' color:red ' >hello world!</div>")

Result: Hello world!

2. @html. ActionLink generates a <a href= "..." ></a> Tags:

such as: @Html. ActionLink ("LinkText", "ActionName", "ControlName", new {id = "911"},new{target= "_blank"})

Result: <a href = "/controlname/actionname/911" >linkText</a>

3. @Url. Action returns a URL

such as: @Url. Action ("ActionName", "ControlName", new {id = "911"})

Results:/controlname/actionname/911

4. @Html. Action loads the local page, the code for the public part, for example: Header/footer/menu/logout ...

such as: @Html. Action ("ActionName", "ControlName")

Usage similar to @html.renderaction

5. @Html. renderaction

such as: @{html.renderaction ("_vspartial", "Cmcontroller");}

_vspartial content:

@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

Principle: Executes according to the order of Controller→model→view, then returns the result

6. @Html. renderpartial

Embed the user control directly into the current page

such as: @{html.renderpartial ("_patientmrpartial");}

_patientmrpartial content:

<Div>    <Div>        <Div>            <H3class= "Pull-left">Hello world!</H3>        </Div>    </Div>    <Div>        <Div>            <Div>                <Div>                    <Div>Tom</Div>                </Div>            </Div>        </Div>        <Divclass= "Row Cpnmedication-content-line">            <Div>                <Div>                    <Divclass= "Pull-left">Jim</Div>                </Div>            </Div>        </Div>    </Div></Div>
View Code

C # ASP. NET MVC HtmlHelper Usage Summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.