Reprint ASP. net mvc Learning (5): HTML. actionlink

Source: Internet
Author: User
Tags actionlink

From http://www.liuwu.net/post/aspnet-mvc-learning-5-html-actionlink.aspx

This article lists several methods of this method:

One html. actionlink ("linktext", "actionname ")

The first parameter of this overload is the text to be displayed on the link, and the second parameter is the method of the corresponding controller. The default controller is the controller of the current page. If the controller of the current page is products, then HTML. actionlink ("detail", "detail") generates <a href = "/products/detail"> all </a>

Html. actionlink ("linktext", "actionname", "controlname ")

This overload has an additional parameter than the first overload. It specifies the Controller name, such as HTML. actionlink ("detail", "detail", "Products") generates <a href = "products/detail"> all </a>

3. html. actionlik ("linktext", "actionname", routevalues)

Routevalue can pass parameters to actions, such as HTML. actionlink ("detail", "detail", new {id = 1}) generates <a href = "products/detail/1"> detail </a>, assume that the current controller is products.

4. html. actionlink ("linktext", "actionname", routevalues, htmlattributes)

Htmlattribute can be used to set <A> tag attributes, such as HTML. actionlink ("detail", "detail", new {id = 1}, new {target = "_ blank "}) <a href = "products/detail/1" target = "_ blank"> detail </a> is generated, the main requirement is that if you write new {target = "_ blank", class = "classname"}, an error is returned. Because class is a keyword, it should be written as @ class = "classname" here ".

5. html. actionlink ("linktext", "actionname", "controlname", routevalues, htmlattributes)

This overload contains all the parameter types mentioned above

6. html. actionlink ("linktext", "actionname", "controlname", "protocol", "hostname", "fragment", routevalues, htmlattributes)

This overload is rarely used. You can specify the access protocol, domain name, and anchor, such as HTML. actionlink ("liuwu", "detail", "Products", "HTTP", "www. liuwu. me "," name ", null, null) can generate <a href =" http://www.liuwu.me/Products/Detail#name "> liuwu </a>

Related Article

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.