1

我有一个带有复选框的页面,用户应该检查并显示一个弹出窗口。弹出的窗口显示正确;但是,我无法关闭窗口。正如您在下面看到的,只要用户单击提交,就会调用 closewindow 函数。显示消息,但窗口永远不会关闭。请参阅下面的示例代码。

//This is the content of the partial page that is being load in the popped up window.
@using (Html.BeginForm("StudentArchive", "Arvhive", FormMethod.Post, new { onsubmit = "CloseWindow()" }))
{

    @Html.HiddenFor(item => item.StudentID)
<table>
    <tr>
        <th>
            Student Archive Reason
        </th>
    </tr>
    <tr>
        <td>
            @Html.TextAreaFor(item => item.ArchiveReason)
        </td>
    </tr>
</table>

 <input type="submit" value="Submit" name="btnSubmit" id="ArchiveReasonSubmit" onclick="CloseWindow();" />
}


      <script type="text/javascript">
          function CloseWindow() {
              alert('I am closing window in reason for archive');
              $("#Window").data("tWindow").close();
//              $('#Window').prop("checked", "checked");
//              window.location.href = window.location.href;
          }
    </script>



//this script is in a studentDetails page which is where the checkbox that would open the window below located.



<script type="text/javascript">
    function chkArchive() {
        var s = document.getElementById('archiveCheckBox').checked;
        if (s == true) {
            OpenWindow(this);
        }

        if (s == false) {
            alert('checkbox is unchecked');
        }
    }
</script>


<script type="text/javascript">
        function OpenWindow(e) {
            var checkbox = document.getElementById('archiveCheckBox').value;
            if (checkbox == "false") {
                alert('It is false.');
            } else if (checkbox == "true") {
                $('#Window').data('tWindow').center().open();
            } 
        }
</script>

    <script type="text/javascript">
        function ClosingWindow() {
            $('#Window').prop("checked", "checked");
            window.location.href = window.location.href;
        }
    </script>


  @{Html.Telerik().Window()
  .Name("Window")
  .Visible(true)
  .Title("Reason for Archives")
  .Modal(true)
  .Height(600)
  .Draggable(true)
  .Visible(false)  //I could have added a variable set the default value to false to hide the window. However, I am not sure how to change it back to 
                   //yes after the user checks the checkbox for the first time. The only event that fire when a user check the checkbox is the javascript event to check the state
                   // of the checkbox and open the window.
  .Width(800)
  .ClientEvents(events => events.OnClose("ClosingWindow"))
  .LoadContentFrom(Url.Action("StudentArchive", "Student", new { StudentID = @ViewData["StudentID"] }, Request.Url.Scheme))
  .HtmlAttributes(new { onsubmit = "CloseWindow()" })
  .Render();
  }
4

1 回答 1

0

jquery 库被引用了两次。我从部分视图页面中删除了它,并且查询工作正常。这是帮助我解决问题的链接:

http://www.telerik.com/community/forums/aspnet-mvc/window/close-modal-window-from-within-the-window.aspx

于 2013-02-10T23:32:33.083 回答