How to get relative path in ASP.NET MVC

How do you calculate relative path in ASP.NET MVC?

+4
source share
2 answers

To include an image or script or any other file, this is the code:

<script src="<%= Url.Content("~/Scripts/tiny_mce/jquery.tinymce.js") %>" type="text/javascript"></script> 
+4
source

also, if you want a relative path inside your controller, you can use:

 string pathName = VirtualPathUtility.ToAbsolute(string.Format(@"~/images/PhotoAlbum/{0}/", propertyId)); 

or

 string pathName = VirtualPathUtility.ToAppRelative(string.Format(@"~/images/PhotoAlbum/{0}/", propertyId)); 

depending on your need.

hope this helps.

+13
source

All Articles