RedirectToAction - 但我希望它转到 http://example.com/controller/action/id?

发布于 2024-07-26 16:17:27 字数 694 浏览 7 评论 0原文

我想将 ASP.NET MVC 响应移至

http://example.com /emails/list/[电子邮件受保护]

使用 RedirectToAction("list", "emails", new { id = "< a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a9dbc6cbe9ccc4c8c0c587cac6c4">[电子邮件受保护]"}); 带您前往 http://example.com/emails/[电子邮件受保护]

我究竟做错了什么?

谢谢,

罗布

I'd like to move an asp.net mvc response to

http://example.com/emails/list/[email protected]

Using RedirectToAction("list", "emails", new { id = "[email protected]"}); takes you to http://example.com/emails/[email protected].

What am I doing wrong?

Thanks,

Rob

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

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

发布评论

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

评论(2

仙气飘飘 2024-08-02 16:17:28

啊 - 因为默认路由需要'id',所以你在视图(html)和控制器中的参数必须称为id。

Ah - because the default route requires 'id', your parameters in the view (html) and the controller must be called id.

装纯掩盖桑 2024-08-02 16:17:27

好像路由配置错误。 Global.asax.cs 中的 RegisterRoutes 方法应如下所示:

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "Default",                                              // Route name
            "{controller}/{action}/{id}",                           // URL with parameters
            new { controller = "Account", action = "Login", id = "" }  // Parameter defaults
        );

    }

在“{controller}/{action}/{id}”行中,存在 {id} 意味着将被替换为值。

路由字符串中不存在的任何其他参数将被解码为 ?some_param=value

Seems like misconfigured routing. Your RegisterRoutes method in Global.asax.cs should look like this:

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "Default",                                              // Route name
            "{controller}/{action}/{id}",                           // URL with parameters
            new { controller = "Account", action = "Login", id = "" }  // Parameter defaults
        );

    }

In line "{controller}/{action}/{id}" presence of {id} means that is going to be substituted by it's value.

Any other parameter that is not present in routing string would be decoded as ?some_param=value

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