Access HtmlHelpers from WebForm when using ASP.NET MVC

asp.net, asp.net-mvc, webforms

Solution

Try something like this in your Webform:

<% var requestContext = new System.Web.Routing.RequestContext(
       new HttpContextWrapper(HttpContext.Current),
       new System.Web.Routing.RouteData());
   var urlHelper = new System.Web.Mvc.UrlHelper(requestContext); %>

<%= urlHelper.RouteUrl(new { controller = "Controller", action = "Action" }) %>

Problem

I am adding a WebForm from which I would like to resolve routes to URLs. For example, in MVC I would just use ``` return RedirectToAction("Action", "Controller"); ``` So, if you have a way of getting to that same URL from a WebForm in the same application, it would be appreciated.

Original source

Related problems