0

I have an existing web forms web application. I want to make a slow transition over to mvc3. To make that happen, I'd like to able to from my old user control (System.Web.UI.UserControl) link in my new mvc3 content with Html.Action and Html.Render. Is it possible? Any hackish solution would do.

Jonas Lincoln
  • 9,567
  • 9
  • 35
  • 49

1 Answers1

1

Something along these lines should work for an UrlHelper; 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); %>

I imagine the same should work for the HtmlHelper; otherwise just use the Url.RouteUrl method:

<a href="<%= urlHelper.RouteUrl(new { controller = "Controller", 
    action = "Action" }) %>">To the MVC app!</a>

For the record, I got it from the following answer: Access HtmlHelpers from WebForm when using ASP.NET MVC

Community
  • 1
  • 1
Sergi Papaseit
  • 15,999
  • 16
  • 67
  • 101