I’m dealing with a web application that resides within a subdirectory on a domain, and I’m attempting to discern the most idiomatic way of inserting a proper URL into an img tag. While the following both produce the same HTML on the client machine, I’m not sure which is more “correct”
<img src="~/Content/images/blah.png" /><img src="@Url.Content("~/Content/images/blah.png")
Both of these produce an absolute path of /subfolder/Content/images/blah.png, so both work, but I’m curious which one is the right way of doing it.
Is there any difference between these two approaches (for example, is one being resolved by a different mechanism than the other?), or is the former just syntactic sugar for the latter?
With MVC4 you no longer need
@Url.Contenthttp://www.beletsky.net/2012/04/new-in-aspnet-mvc4-razor-changes.html