Access HtmlHelpers from WebForm when using ASP.NET MVC

前端 未结 3 1548
鱼传尺愫
鱼传尺愫 2020-12-10 16:24

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\", \"Control         


        
3条回答
  •  甜味超标
    2020-12-10 16:54

    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" }) %>
    

提交回复
热议问题