【问题标题】:Why RedirectToAction loses the relative path of the app为什么 RedirectToAction 会丢失应用程序的相对路径
【发布时间】:2016-03-11 19:44:07
【问题描述】:

我想从一个控制器将用户带到应用程序中的另一个页面,所以我说的是:

return RedirectToAction("Index","ThatPage");

我检查了ThatPageControllerIndex 确实存在。 但它会将浏览器带到 URL:http://thatpage/

发生了什么事?

【问题讨论】:

  • 请发布您的路由配置(包括任何区域和属性路由)。另外,ThatPage 之前没有双引号是错字吗,还是您的实际代码?

标签: c# asp.net-mvc routing


【解决方案1】:

您想要转到另一个控制器的 RedirectToAction 的重载和该控制器中的一个方法有两个单独的字符串作为参数。

你会想写:

return RedirectToAction("Index", "Home");

您在方法签名中缺少 " 标记。

【讨论】:

  • 哦,那只是手写输入错误!但是感谢我发现了这个问题,这不是 SO 的标准 MVC 问题,而是一些内部内部代码导致它。
【解决方案2】:
This example when user closes a session
   public async Task<ActionResult> Logout()
        {
          return RedirectToAction("Index", "App");
        }

where APP is the controller and Index is the action where I have within the App controller
Appcontroller:

 in App controller I have this   

public IActionResult Index()
        {
            return View();
        }

【讨论】:

    猜你喜欢
    • 2012-05-26
    • 1970-01-01
    • 2016-08-30
    • 1970-01-01
    • 2019-01-06
    • 2011-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多