有没有办法在 ASP.Net Forms 页面中使用 RedirectToAction 或等效内容?

发布于 2024-10-21 05:20:13 字数 178 浏览 1 评论 0原文

我有一个包含 Forms 和 MVC v2 页面的混合环境。我想从表单页面重定向到 MVC 页面。

通常我在控制器内使用 RedirectToAction。但是当我在 Asp.Net Forms 类型页面中时,我无法真正使用它。

我正在挖掘框架来寻找解决方案,我想我会在这里问,以防有人已经知道这个问题的答案。

I have a mixed environment with both Forms and MVC v2 pages. I want to redirect to a MVC page from a Forms page.

Usually I use RedirectToAction when within the controller. But when I am in a Asp.Net Forms type page I can't really use that.

I'm digging around the framework to find a solution, thought I would ask here in case someone already knows the answer to this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晨曦÷微暖 2024-10-28 05:20:13

我自己找到了答案。我是这样解决这个问题的:

var controllerName = "NameOfMyController";
var actionName = "NameOfMyAction";

//Lets resolve the URL for the controller/action based on the existing routes
var routes = RouteTable.Routes;
var virtualPathData = routes.GetVirtualPath(
                        null,
                        new RouteValueDictionary {
                                {"Controller", controllerName}, 
                                {"Action", actionName}
                        });

/* resolvedUrl should now contain the full URL to 
the controller/action defined at the beginging */
var resolvedUrl =  virtualPathData == null ? "" : virtualPathData.VirtualPath;

I found the answer on my own. Here is how I solved this:

var controllerName = "NameOfMyController";
var actionName = "NameOfMyAction";

//Lets resolve the URL for the controller/action based on the existing routes
var routes = RouteTable.Routes;
var virtualPathData = routes.GetVirtualPath(
                        null,
                        new RouteValueDictionary {
                                {"Controller", controllerName}, 
                                {"Action", actionName}
                        });

/* resolvedUrl should now contain the full URL to 
the controller/action defined at the beginging */
var resolvedUrl =  virtualPathData == null ? "" : virtualPathData.VirtualPath;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文