Some methods of link in Razor syntax, razor syntax Link

Source: Internet
Author: User
Tags actionlink

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 ")


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