What is the difference between "@Url.Content" and "@Href"?

asp.net, css, href, razor, url-routing

Solution

Both are similar except Url.Content works with applications's virtual directory. `@Href` comes from the System.Web.WebPages library and `@Url.Content` is part of the MVC.

@Url.Content is my favorite.

Problem

It seems that stylesheets can be referenced razoresque either this way: ``` <link href="@Url.Content("~/Content/jquery.duckbilledplatypus.css")" rel="stylesheet" type="text/css" /> ``` ...or this way: ``` <link href="@Href("~/Content/jquery.duckbilledplatypus.css")" rel="stylesheet" type="text/css" /> ``` Is there an advantage to one way over the other? I noticed that I had this, too: ``` <script src="@Url.Content("http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js")" type="text/javascript" defer ></script> ``` ...which is probably bogus (the razoresque-ization of the href that way), as the file on the CDN doesn't need to be razorized.

Original source