【问题标题】:MVC Response.Redirect not working with question markMVC Response.Redirect 不适用于问号
【发布时间】:2014-06-09 20:43:47
【问题描述】:

我正在尝试从控制器重定向到另一个页面,代码是:

Response.Redirect("http://server1:8080/amj/servlet/inv/template/print.html?txt=ABC");

但是重定向到这个网址:

http://server1:8080/amj/servlet/inv/txt/ABC/template/print.html

如您所见,它将 txt=ABC 放在字符串的中间...

如果我尝试使用不带问号的网址,它可以正常工作。

提前感谢您的帮助。

问候

卡洛斯。

【问题讨论】:

  • 您为什么在 MVC 应用程序中使用 Response.Redirect,您可以使用适当的 ActionResults 来处理您的控制器操作应该返回?
  • 网址就是网址。如果它在此过程中发生变化,则意味着还有其他一些重定向在起作用。这里没有足够的信息来诊断。

标签: asp.net-mvc url-redirection response.redirect


【解决方案1】:

你可以试试下面的。控制器的ActionResult 可以返回包含重定向链接的Content 类型。

public ActionResult RedirectPage(long param)
{
     string url = "http://server1:8080/amj/servlet/inv/template/print.html?id=" + param;
     return Content("<html><script>window.location.href = '" + url + "';</script></html>");
}

【讨论】:

    【解决方案2】:

    查询字符串参数与您的路由设置中的路由之一匹配。

    您可以通过在 RegisterRoutes 方法中使用 routes.IgnoreRoute 来解决特定页面/路由的问题。

    另一种选择是不使用 Response.Redirect 而是使用 Controller/Action 路由模型。这将是首选方法,您可以在this 文章中阅读更多有关原因的信息。

    【讨论】:

      猜你喜欢
      • 2013-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-19
      • 2012-12-20
      • 2011-04-18
      • 2018-09-17
      相关资源
      最近更新 更多