The Html.ActionLink__.net of ASP.net MVC

Source: Internet
Author: User

@Html. ActionLink has 10 overloads.

Sample Code Description
@Html. ActionLink ("LinkText", "ActionName")

In a generated hyperlink, the text specified by linktext cannot be null or empty, or the program will complain

@Html. ActionLink ("Blog Park", "Index"), generate a hyperlink to the first page

@Html. ActionLink ("LinkText", "ActionName"),
"Controllername")
@Html. ActionLink ("homepage", "index", "Home") <a href= "Home/index" > Home </a>
@Html. ActionLink ("LinkText", "ActionName"),
"Controllername", "Routvalues", "Htmlattributes")

This is a much more used approach because you can define ActionName and controllername, and you can set values for route and Htmlattribute.

@Html. ActionLink ("homepage", "index", "Home", new{id= "one", Name= "Tom"},new{@class = "Btnlogin", data_val= "Guozhqi" id= " Btnlogin "})

<a href= "Home/index/11?name=tom" class= "Btnlogin" id= "Btnlogin" data-val= "Guozhiqi" > Home </a>

Note: When htmlattribute Add class, you need to add the @ in front of the class

Note the parameter types in the method should be noted when choosing the appropriate overload, because there are many object types in the overload


















Question: Can you generate a hyperlink with no display text by using @html.actionlink (). The answer is no, because in Html.ActionLink, the text must be filled in and not allowed to be empty. It can be implemented indirectly by using the <a href= "@Url. Action (" Index "," Home ")" class= "Btnlogin" ></a>.

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.