开发者

How to get the value of ~ in an mvc view?

开发者 https://www.devze.com 2023-01-22 17:40 出处:网络
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

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

精彩评论

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