使用ASP.NET MVC时从Web窗体访问HtmlHelpers [英] Access HtmlHelpers from WebForm when using ASP.NET MVC

查看:99
本文介绍了使用ASP.NET MVC时从Web窗体访问HtmlHelpers的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加一个WebForm从中我想解决路线的URL。例如,在MVC我只想用

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");

所以,如果你获得到相同的URL,从一个WebForm在同一应用程序的一种方式,这将是AP preciated。

So, if you have a way of getting to that same URL from a WebForm in the same application, it would be appreciated.

推荐答案

尝试这样的事情在你的网络表单:

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

这篇关于使用ASP.NET MVC时从Web窗体访问HtmlHelpers的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆