Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get current virtual path in ASP.NET MVC?

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?

EDIT

I don't want the protocol and host portion of the url.

like image 727
Ronnie Overby Avatar asked Dec 09 '22 19:12

Ronnie Overby


1 Answers

This will return the url in the view for you:

'<%=Url.RouteUrl(ViewContext.RouteData.Values)%>
like image 86
tuanvt Avatar answered Jan 04 '23 23:01

tuanvt