Using Url.Action only generates the Url potion. You still have to write th tag by hand . Using Html.ActionLink creates the entire <a href.. tag for you.In both cases you can pass route data and it will format the parameters correctly.
If you decided to switch to an Ajax solution later, I think it's easier since you are just changing Html.ActionLink to Ajax.ActionLink and passing a few extra parameters.
There have been cases where i've had to generate the entire html link string by hand and in that instance I used Url.Action, but for the most part I stick to Html.ActionLink.
It Really it depends on your needs and personaly style, but I don't think there is any big difference.
ProgrammerOn...
Member
13 Points
80 Posts
Url.Action vs Html.ActionLink
Dec 06, 2009 07:31 PM|LINK
Is there any advantage or disadvantage in using either one over the other?
CodeHobo
All-Star
18647 Points
2647 Posts
Re: Url.Action vs Html.ActionLink
Dec 06, 2009 07:44 PM|LINK
Using Url.Action only generates the Url potion. You still have to write th tag by hand . Using Html.ActionLink creates the entire <a href.. tag for you.In both cases you can pass route data and it will format the parameters correctly.
If you decided to switch to an Ajax solution later, I think it's easier since you are just changing Html.ActionLink to Ajax.ActionLink and passing a few extra parameters.
There have been cases where i've had to generate the entire html link string by hand and in that instance I used Url.Action, but for the most part I stick to Html.ActionLink.
It Really it depends on your needs and personaly style, but I don't think there is any big difference.
Blog | Twitter : @Hattan
ali62b
Contributor
4750 Points
690 Posts
Re: Url.Action vs Html.ActionLink
Dec 09, 2009 07:52 AM|LINK
When using ActionLink, your route will be determined for you, based on the first
matching route defined in the route collection. Most often this will be sufficient, but if
you want to request a specific route, you can use RouteLink. RouteLink accepts a
parameter to identify the route requested, like this:
<%= Html.RouteLink("WDG003", "special-widget-route",
new { widgetCode = "WDG003" }, null) %>
This will look for a route with the name special-widget-route. Most often you will not
need to use this technique unless the URL generated by routing is not the desired
one. Try to solve the issue by altering route ordering or with route constraints. Use
RouteLink as a last resort.
Sometimes you need to obtain a URL, but not for the purposes of a link or form.
This often happens when you are writing AJAX code, and the request URL needs to be
set. The UrlHelper class can generate URLs directly, and in fact the UrlHelper is used
by the ActionLink methods and others. Here is an example:
<%= Url.Action("show", "catalog",
new { widgetCode="WDG0002", language="fr" }) %>
This will return the same URL as above, but without any surrounding tags.
from book "ASP.NET MVC In Action"--> page.137
hope this helps
Html.ActionLink url.action html.RouteLink
@BlueCoder
Regards