【问题标题】:Redirect To Action Not Working Based On Provided Path根据提供的路径重定向到操作不起作用
【发布时间】:2021-09-16 00:36:45
【问题描述】:

当前页面重定向不起作用。页面 URL 位于 http://localhost:40823/Account/SignIn。该页面根本没有重定向。我不知道为什么这种方法没有重新路由。有任何想法吗?我设置了一个断点并遍历了我的代码,它到达了 return 语句,但它不起作用。我在其他地方使用过它,它工作得很好。我只是在这里复制了 return 语句,但它不起作用。

    [HttpPost]
    public ActionResult PasswordRequest(string email)
    {
        Player player= GetPlayer();

        try
        {
            player.Email = Login.EmailAddress = email;
            ResetPassword(player);
        }
        catch(Exception ex) {
             console.log("Error")
        }

        return RedirectToAction("SignIn", "Account");
    }

【问题讨论】:

  • 您是否尝试输入localhost:40823/Account/SignIn。在浏览器中?
  • @Serge 是的,我做到了。如果手动完成,它可以工作。
  • 如何调用 PasswordRequest 操作?提交按钮还是别的什么?
  • “如果手动完成则不起作用”但如果它完全起作用?
  • @Serge 我在 JavaScript 中使用 fetch 调用。如果我设置了 window.location.href 它可以正常工作,但重定向操作将不起作用。

标签: c# asp.net asp.net-mvc asp.net-core


【解决方案1】:

您正在使用 ajax 调用 PasswordRequest 操作,ajax 忽略所有重定向并始终返回成功:或错误 javascript 函数。如果要在控制器内部使用重定向,则必须使用提交按钮或 ancor 标签来调用 PasswordRequest。另一种方法是在成功 ajax 函数中分配 window.location.href =http://localhost:40823/Account/SignIn。

【讨论】:

    猜你喜欢
    • 2014-05-31
    • 1970-01-01
    • 1970-01-01
    • 2021-07-31
    • 2015-08-12
    • 2015-10-30
    • 2014-01-27
    • 1970-01-01
    • 2020-07-23
    相关资源
    最近更新 更多