Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 在ASP.NET MVC中关闭当前视图_Asp.net Mvc - Fatal编程技术网

Asp.net mvc 在ASP.NET MVC中关闭当前视图

Asp.net mvc 在ASP.NET MVC中关闭当前视图,asp.net-mvc,Asp.net Mvc,我有一个页面叫PayOut.cshtml。在这个页面上,我有一个名为Pay的按钮,它打开了一个名为Authenticate.cshtml的新窗口,用户可以通过指定电子邮件和密码对自己进行身份验证 一旦用户通过身份验证,Authenticate.cshtml将被取消,并在PayOut.cshtml页面中显示一个名为Confirm的按钮 我尝试了以下方法: public AuthenticateController(Authenticate obj) { var success = fa

我有一个页面叫PayOut.cshtml。在这个页面上,我有一个名为Pay的按钮,它打开了一个名为Authenticate.cshtml的新窗口,用户可以通过指定电子邮件和密码对自己进行身份验证

一旦用户通过身份验证,Authenticate.cshtml将被取消,并在PayOut.cshtml页面中显示一个名为Confirm的按钮

我尝试了以下方法:

public AuthenticateController(Authenticate obj)
{
      var success = false;

      if (auth) {
         success = true;
      }

      return View("close");
}
关闭视图:

<body>
    <script type="text/javascript">
        window.close();
    </script>
</body>

我如何通过使用会话在authenticate视图中取消验证并在PayOut视图中显示按钮?请帮助。

出于安全原因,规范实际上不允许这样做。尽管如此,我只是用Edge、Chrome、Firefox和IE进行了测试,效果不错。你能解释一下它是怎么不起作用的吗

无论如何,我决定尝试另一种方法,它不需要一个窗口试图关闭自己,它在相同的四个浏览器中工作

在Payout.cshtml中

   var newWindow;
    function authenticate() {
        newWindow = window.open("@Url.Action("Authenticate")");
        window.setTimeout(tryCloseWindow, 5000);
    }
    function tryCloseWindow() {
        try {
            if (newWindow.closeMe == undefined) {
                window.setTimeout(tryCloseWindow, 1000);
                return;
            }
        } catch(ex) {
            // window was closed by user
            return;
        }

        newWindow.close();
    }
Authenticate.cshtml

<button onclick="pay();">pay</button>

@section Scripts
{
    <script>
        function pay() {
            window.location = "@Url.Action("Close")";
        }
    </script>
}
Close.cshtml

@section Scripts
{
    <script>
        window.closeMe = true;
    </script>
}

您可以使用postMessage,在主窗口中使用如下内容:

<!DOCTYPE html>
<html>
   <header>
      <title>PostMessage Demo</title>
  </header>
  <body>
    <button id="btn" onclick="openPopup();">Open Popup</button>
    <script>

        window.addEventListener("message", onMessage, false);

        function onMessage(event){
            document.getElementById("btn").innerText = "you typed " + event.data;
            document.getElementById("btn").disabled = false;
        };

        function openPopup(){
            document.getElementById("btn").textContent = "popup active";
            document.getElementById("btn").disabled = true;
            window.open("/popup", "popup window");
        }

     </script>
   </body>
</html>
然后在弹出窗口中:

<!DOCTYPE html>
<html>
    <header>
        <title>Popup</title>
    </header>
    <body>
        <input id="textEdit" type="text" value=""></input>
        <button onclick="_close();">Close popup</button>
        <script>

            function _close(){
            let pUri = window.location.protocol + "//" + window.location.host + "/";
            window.opener.postMessage(document.getElementById("textEdit").value, pUri);
            window.close();
        }

        </script>
    </body>
</html>

当您单击弹出窗口中的关闭弹出按钮时,它将关闭并触发主窗口中的onMessage事件,其中包含您在textEdit输入中键入的文本。

我如何显示按钮确认弹出窗口何时关闭?在newWindow.Close之后,假设您有一个隐藏的按钮,document.getelementbyidconfirbutton.style.display=block;