@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>.