How to get the value of ~ in an mvc view?
I need to get the absolute path of the root in an asp.net mvc view
I开发者_Go百科 guess one way would be to do Url.Action("Index","Home")
and will get
http://localhost/myapp
anybody knows the right way ?
Url.Content()
will give you that. It's intended to allow you to get the path for static files, such as
<img src='<%: Url.Content("~/images/logo.gif") %>' />
Calling Url.Content("~")
will return /myapp/
, or just /
if your application isn't in a virtual directory.
I think you can use
string urlBase = Request.Url.GetLeftPart( UriPartial.Authority ) + Request.ApplicationPath;
精彩评论