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

查看:18
本文介绍了使用 ASP.NET MVC 时从 WebForm 访问 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");

因此,如果您有办法从同一应用程序中的 WebForm 获取相同的 URL,我们将不胜感激.

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 时从 WebForm 访问 HtmlHelpers的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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