asp.net mvc - Get absolute path of file on content -
is there easy (built in) way in asp.net mvc view absolute path of file in content folder?
at moment i'm using
@url.content("~/content/images/logo.png")
but path returned isn't absolute.
i know possible build own helper such cases i'd know if there's easier way...
this works me:
a helper:
using system; using system.web; using system.web.mvc; public static class urlextensions { public static string content(this urlhelper urlhelper, string contentpath, bool toabsolute = false) { var path = urlhelper.content(contentpath); var url = new uri(httpcontext.current.request.url, path); return toabsolute ? url.absoluteuri : path; } }
usage in cshtml:
@url.content("~/scripts/flot/jquery.flot.menubar.js", true) // example output: // http://example.com/directory/scripts/flot/jquery.flot.menubar.js
Comments
Post a Comment