Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Href and Url.Content?

Tags:

asp.net-mvc

Both Href and Url.Content can be used to resolve a virtual path, which is relative to the virtual root path ~, of files or folders.

What is the difference between Href and Url.Content ?

like image 421
LaTeX Avatar asked Feb 03 '11 06:02

LaTeX


People also ask

What is the difference between URL and href?

Both the link text and the URL are defined within an HTML anchor element <a> . The HTML anchor element contains a href attribute with a value as its source — and the value is the URL that takes the person clicking on it to the destination you have defined.

What is content in URL?

Url.Content is used when you wish to resolve a URL for any file or resource on your site and you would pass it the relative path: @Url.Content("~/path/file.htm") Url.Action is used to resolve an action from a controller such as: @Url.Action("ActionName", "ControllerName", new { variable = value })

What is the difference between href and SRC in HTML?

HREF - Hyperlink Reference | Often used in tags to reference another page or web link. SRC - Source | Often used in tags to give the web page the source of an image, video or file.

Is URL same as SRC?

The href attribute specifies the location (URL) of a resource, that an anchor element points to, or the location of a linked resource, like a stylesheet. While the src attribute is used to embed a resource - usually URLs - into a document, think embedded images ( <img> ) and <script> tags.


1 Answers

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.

like image 196
stoic Avatar answered Oct 26 '22 09:10

stoic