Link mvc3 views from web form user control
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 co开发者_如何学Gontrol (System.Web.UI.UserControl) link in my new mvc3 content with Html.Action and Html.Render. Is it possible? Any hackish solution would do.
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
精彩评论