RedirectToAction 有哪些替代方案?

发布于 2024-09-07 13:29:17 字数 355 浏览 4 评论 0原文

在我的 HomeController 上,我有一个索引操作,它通过 RedirectToAction 方法重定向到 CustomerController 的索引操作。在本例中,我不喜欢 RedirectToAction 修改显示 mysite.com/Customer 的 URL。是否有一些替代机制来执行重定向,使我仍然可以利用 CustomerController 中的索引操作?

public RedirectToRouteResult Index()
{
    return RedirectToAction("Index", "Customer");
}

On my HomeController I have an index action which redirects to the index action of the CustomerController via the RedirectToAction method. In this instance I don't like how RedirectToAction modifies the URL showing mysite.com/Customer. Are there some alternative mechanisms to performing a redirection that will allow me to still leverage the index action from the CustomerController?

public RedirectToRouteResult Index()
{
    return RedirectToAction("Index", "Customer");
}

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

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

发布评论

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

评论(1

凡间太子 2024-09-14 13:29:17

据我了解,RedirectToAction 使用路由表上的反向查找来生成其 URL。因此,如果您告诉路由模块您想要将“/Customer/Index”映射到控制器 Customer 和 Action Index,则 RedirectToAction 将获取您的 Index 和 Customer 参数并将它们转换为“/Customer/Index”。

因此,如果您想更改 RedirectToAction 的行为,您只需更改路由规则即可。

As I understood it, RedirectToAction uses a reverse lookup on the routing table to generate its URL. So if you've told the Routing module that you want to map "/Customer/Index" to Controller Customer and Action Index then RedirectToAction will take your Index and Customer arguments and convert them to "/Customer/Index".

So if you want to change the behaviour of RedirectToAction you simply need to change your routing rules.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文