Hyperlinks
are a common requirement in any webpage, in general we use the <a href>
tag to create hyperlinks from one page to another, Asp.Net MVC still allows this type of hyperlinks in addition it
provides 2 other ways of adding Hyperlinks in a page.
1. Using the Html.ActionLink 2. Using the Url.Action
The Html.ActionLink method generates a full <a href=””> tag and places in the page, while Url.Action() just returns the URL for the specified controller and action. Hence while using the Url.Action() method we need to explicitly form the tags and text around the Hyperlink.
In the View page, always use Html.ActionLink, the Url.Action method can be used in the controller page when you need to get the full URL for a specific Controller and Action. The Url.Action method can also be used in Ajax requests where we just need the URL to be passed for Ajax requests.
Example
Html.ActionLink
<%= Html.ActionLink("Register", "Index","User") %>
Url.Action
<a href="<%= Url.Action("Index","User")%>">Register</a>
No comments:
Post a Comment