@html. Several parameter formats for ActionLink

Source: Internet
Author: User
Tags actionlink

A Html.ActionLink ("LinkText", "ActionName")

The first parameter of the overload is the text to be displayed for the link, and the second parameter is the method of the corresponding controller.

The default controller is the controller of the current page, Html.ActionLink ("detail", "detail") if the controller for the current page is products

The <a href= "/products/detail" is generated >detail</a>

Two Html.ActionLink ("LinkText", "ActionName", "ControlName")

The overload has one more parameter than the first overload, and he specifies the name of the controller,

such as Html.ActionLink ("detail", "detail", "products") will generate

<a href= "Products/detail" >detail</a>

Three Html.actionlik ("LinkText", "ActionName", routevalues)

RouteValue can pass arguments to action, such as Html.ActionLink ("detail", "detail", new {id=1})

Will generate <a href= "PRODUCTS/DETAIL/1" >DETAIL</A>

Here it is assumed that the current controller is products.

Four Html.ActionLink ("LinkText", "ActionName", Routevalues,htmlattributes)

Htmlattribute can set the properties of <a> tags, such as html.actionlink ("detail", "detail", new{id=1},

new{target= "_blank"}) generates

<a href= "PRODUCTS/DETAIL/1" target= "_blank" >DETAIL</A> the main need is if written

new{target= "_blank", class= "ClassName"} will be an error,

Because class is a keyword, it should be written here @class = "ClassName".

Five Html.ActionLink ("LinkText", "ActionName", "ControlName", Routevalues,htmlattributes)

This overload contains all of the parameter types mentioned above


Vi. Html.ActionLink in use, where the linktext is the link to display content, such as Html.ActionLink (" Jump to About page", "about"), the result is: <a href= "/home/ About "> Jump to About page </a>, so you can see in detail linktext for the link to display the text.


Vii.Html.ActionLink When used if there is no contorlname in the overloaded parameter, the resulting linked controller is the current default controller

This article is from the "One Foot § Scarecrow" blog, please be sure to keep this source http://xyh1993.blog.51cto.com/7883839/1793902

@html. Several parameter formats for ActionLink

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.