Some methods of link in Razor syntax, razor syntax Link
In Razor, there are HTML. ActionLink and Url. Action to render the link. What are their differences. If you can clearly distinguish them, you will know under what circumstances to use them.
First, let's take a look at html. ActionLink. This method loads a lot and generates a <a href = "..."> </a> tag.
If no controller is specified, the Controller corresponding to this page is used by default.
Method 1: Html. ActionLink ("link text", "actionName ")
Method 2: Html. ActionLink ("link text", "actionName", "controlName ")
Method 3: Html. ActionLik ("link text", "actionName", routeValues)
RouteValues is a routeValue parameter that can be passed to action, for example, new {id = 1}
Method 4: Html. ActionLink ("link text", "actionName", routeValues, htmlAttributes)
You can set the attribute of the <a> label for the last htmlAttribute parameter in the method.
Method 5: Html. ActionLink ("link text", "actionName", "controlName", routeValues, htmlAttributes)
This is not an example. It is the integrated version of the above versions.
Url. Action returns only one url. You can also specify the Controller to specify the action to return the complete URL address. This url does not include the <a> tag.
The following Insus. NET lists a method overload: Url. Action ("actionName", "controllerName", routeValueDictionary, "protocol", "hostName ")