Mvc relative path using virtual!

Mvc relative path using virtual!

When i drag and drop my image/script/css file into my view, relative path will automatically use to refer on the files.


<link href="../../Content/style.css" rel="stylesheet" type="text/css" />  <script src="../../Scripts/jquery-min.js" type="text/javascript"></script>  <img src="../../Images/logo.jpg" /> 

It is working fine when i host it on my root directory, but if i'm using virtual directory then only my css file able to refer correctly, the rest will return it will refer to http://{root}/Images/logo.jpg rather than http://{root}/{virtual directory}/Images/logo.jpg

But why css file is working? and how to specify the relative path correctly for both root & virtual directory cases?

Localization with separate Language folders within Views


How to create a reusable Asp.Net Mvc application?
something like....
Client Id for Property (ASP.Net MVC)
   <script type="text/javascript"               src="<%= Url.Content ("~/Scripts/jquery.js") %>">    </script>  
will do the trick.
How to redirect if javascript is disabled in mvc masterpage

file upload working in one and not the other help

Can classic asp and ASP.NET MVC run side-by-side on the same site?


Setting a default value — presentation logic or business logic?
Also, related to Kazi Manzur's MVC Best Practices, you could create UrlHelper methods to handle the creation of all of your content (script, stylesheet, images, etc) filepaths.

Suggestions/Recommendations for a Web Application with Sub-Apps
That way, if you change the directory, all you have to do is change the corresponding UrlHelper:.
   public static string Style(this UrlHelper url, string fileName)    {        return url.Content("~/content/{0}".FormatWith(fileName));    }     public static string Script(this UrlHelper url, string fileName)    {        return url.Content("~/scripts/{0}".FormatWith(fileName));    } 
Then, in your ViewPage or MasterPage, you can write the paths like so:.
<link  href="<%= Url.Style("site.css")%>" rel="stylesheet" type="text/css"/> 

68 out of 100 based on 33 user ratings 958 reviews