将整个页面从MVC3 Razor iFrame页面重定向到不同的URL

Lee*_*Lee 5 razor asp.net-mvc-3

我有一个剃须刀页面https://myDomain1.com/myFrame.cshtml,上面 有一个"继续"按钮

这个剃刀页面是另一个parent.cshtml中的iframe

当我点击"继续"按钮时,我想将整个页面(包括父页面)重定向到https://myDomain2.com/default.

下面给出的是我的Controller中的ActionResult

[HttpPost]
    public ActionResult myFrame(TestViewModel model)
    {

      Response.Redirect("https://myDomain2.com/default");

       return View(model);
    }
Run Code Online (Sandbox Code Playgroud)

使用上面的代码,只有页面的iframe部分重定向,但我的要求是将整个页面重定向到https://myDomain2.com/default 我的问题是,我想重定向我的整个页面(包括父页面)到https://myDomain2.com/default.

请帮我了解如何将整个页面重定向到其他域名网址

Ada*_*SFT 7

如果您必须使用此解决方案(坚持使用框架),只需包含javascript内容结果 - 这些内容如下:


    [HttpPost]
    public ActionResult myFrame(TestViewModel model)
    {
       return Content("<html><script>window.top.location.href = "http://www.whatever.com"; </script></html>");
    }

您的框架必须位于同一个域中才能实现此功能.


SLa*_*aks 6

HTTP不允许您在响应中指定目标帧.

相反,设置target="_top"原始<form>,或在目标页面中放置一个Javascript frame-buster.

  • 或者,更好的是,停止使用框架. (2认同)