I'm just wondering about it's use. I'm guessing I can probably implement most of it's functionality through jQuery but I try to use native .NET f/w functionality when practical because it's more expected by more developers and it's usually quicker. So I'm just
wondering about some practical examples of UrlHelper so I can get a better understanding of its use and purpose and get a better understanding of when I can use UrlHelper instead of custom js....
dotnetterAMG...
Member
236 Points
520 Posts
practical uses of urlhelper
Jul 15, 2012 03:15 PM|LINK
Can someone please provide a couple of examples showing practical uses of UrlHelper?
CPrakash82
All-Star
18720 Points
2899 Posts
Re: practical uses of urlhelper
Jul 15, 2012 03:33 PM|LINK
Which method specifically you are looking for?
Thanks,
dotnetterAMG...
Member
236 Points
520 Posts
Re: practical uses of urlhelper
Jul 15, 2012 03:45 PM|LINK
BrockAllen
All-Star
28052 Points
4996 Posts
MVP
Re: practical uses of urlhelper
Jul 15, 2012 04:21 PM|LINK
This is hard to do with @Html.ActionLink, so we the UrlHelper APIs instead:
<a href=@Url.Action("Details", "Movie")>
@Model.MovieName
<img src=@Url.Action("Poster", "Movie") >
</a>
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
dotnetterAMG...
Member
236 Points
520 Posts
Re: practical uses of urlhelper
Jul 16, 2012 12:35 AM|LINK
Thanks Brock - That helps put things in context for me. I created a simple example to compare Url.Action to Html.ActionLink below:
@Html.ActionLink("Click to Test", "TestIt", "Test")
@Url.Action("TestIt", "Test");
Html.ActionLink renders a clickable url configured with the parameters.
Url.Action renders url text (not clickable) so I see how Url.Action would be used to create custom clickable urls....
BrockAllen
All-Star
28052 Points
4996 Posts
MVP
Re: practical uses of urlhelper
Jul 16, 2012 02:36 AM|LINK
It can also be used to render URLs for your JavaScript's Ajax calls.
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
dotnetterAMG...
Member
236 Points
520 Posts
Re: practical uses of urlhelper
Jul 16, 2012 02:49 AM|LINK
sp00k
Participant
1916 Points
435 Posts
Re: practical uses of urlhelper
Jul 16, 2012 08:25 AM|LINK
<input type="button" value="RESET DB" id="reset" />
$('#reset').click(
function () {
$('#dummy').html('<img src="../../Content/Images/loading.gif" />').load('@Url.Action("ResetDB", "Home")');
window.location.reload();
});
dotnetterAMG...
Member
236 Points
520 Posts
Re: practical uses of urlhelper
Jul 16, 2012 01:21 PM|LINK
BrockAllen
All-Star
28052 Points
4996 Posts
MVP
Re: practical uses of urlhelper
Jul 16, 2012 01:27 PM|LINK
Hard coding URLs is somewhat brittle given that you can change the entire app's URL scheme fairly easily with routing.
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/