如何获得在ASP.NET MVC当前虚拟路径? [英] How to get current virtual path in ASP.NET MVC?
本文介绍了如何获得在ASP.NET MVC当前虚拟路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从一个asp.net MVC视图中获取当前路径(URL)?
How do you get the current path (url) from within an asp.net mvc view?
如果没有一种方式来获得它的观点,你怎么能得到它的控制器,以便可以将其传递到视图?
If there isn't a way to get it in the view, how can you get it in a controller so that it can be passed to the view?
我不希望URL的协议和主机部分。
I don't want the protocol and host portion of the url.
推荐答案
这将返回的URL在视图中为您提供:
This will return the url in the view for you:
'<%=Url.RouteUrl(ViewContext.RouteData.Values)%>
这篇关于如何获得在ASP.NET MVC当前虚拟路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文