How do I generate a URL outside of a controller in ASP.NET MVC?

Shawn Mclean picture Shawn Mclean · Feb 5, 2011 · Viewed 25.7k times · Source

How do I generate a URL pointing to a controller action from a helper method outside of the controller?

Answer

L01NL picture L01NL · Feb 6, 2014

You could use the following if you have access to the HttpContext:

var urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext);