应该如何使用 RedirectToRoute? [英] How is RedirectToRoute supposed to be used?

查看:36
本文介绍了应该如何使用 RedirectToRoute?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Global.asax.cs 中有这个:

I have this in my Global.asax.cs:

routes.MapRoute("BetaAccess", "beta-access", new { controller = "Beta", action = "Index" });

这在我的控制器中(HomeController 上的索引操作),它肯定受到了打击:

And this in my controller (index action on HomeController) and it definitely is getting hit:

RedirectToRoute("BetaAccess");

但仍然没有重定向发生...它只是转到正常的主页.我用错了吗?

But still no redirection happens... it just goes to the normal home page. Am I using it wrong?

此外,我可以执行 Response.Redirect("~/beta-access") 并转到测试版页面...

Also, I can do Response.Redirect("~/beta-access") and it goes to the beta page...

推荐答案

RedirectToRoute 返回一个 RedirectToRouteResult.试试这个.

RedirectToRoute returns a RedirectToRouteResult. Try this instead.

return RedirectToRoute("BetaAccess");

这篇关于应该如何使用 RedirectToRoute?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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