Both are similar except Url.Content works with applications's virtual directory. @Href comes from System.Web.WebPages but @Url.Content is part of the MVC. The advise is to use @Url.Content due to its flexibility.
comes from the ASP.NET WebPages stack. In an MVC context you should use
Url.Content
url.content does alot more than just creating an normal href, it takes into context the application's sub/virtual directory, whereas href it's a straight pointer.
for best practice use url.content, this way you know that if your site moves into a sub/virtual directory, your link will still work.
zielony
Member
221 Points
410 Posts
what is the difference between @Url.Content() and @Href?
Dec 15, 2012 09:44 AM|LINK
what is the difference between @Url.Content() and @Href?
CPrakash82
All-Star
18270 Points
2839 Posts
Re: what is the difference between @Url.Content() and @Href?
Dec 15, 2012 04:23 PM|LINK
Both are similar except Url.Content works with applications's virtual directory. @Href comes from System.Web.WebPages but @Url.Content is part of the MVC. The advise is to use @Url.Content due to its flexibility.
RameshRajend...
Star
7983 Points
2099 Posts
Re: what is the difference between @Url.Content() and @Href?
Dec 15, 2012 04:28 PM|LINK
They're quite similar, though Href comes from the ASP.NET WebPages stack. In an MVC context you should use Url.Content.
hiteshvyas
Member
13 Points
11 Posts
Re: what is the difference between @Url.Content() and @Href?
Dec 17, 2012 06:46 AM|LINK
They're quite similar, though
comes from the ASP.NET WebPages stack. In an MVC context you should useurl.content does alot more than just creating an normal href, it takes into context the application's sub/virtual directory, whereas href it's a straight pointer.
for best practice use url.content, this way you know that if your site moves into a sub/virtual directory, your link will still work.