开发者

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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜