Asp.net mvc 3 (';#Window';).data(';tWindow';).close()

Asp.net mvc 3 (';#Window';).data(';tWindow';).close(),asp.net-mvc-3,Asp.net Mvc 3,我有一个电传打字机从窗口弹出。它开得很好;但是,我在关闭窗口时遇到了一个问题。如果我向javascript、alert(“#Window”)或alert($(this).closest(“#Window”)添加一个警报,它将显示[object]。但是,alter(“#Window”).data(“tWindow”)或alert($(this).closest(“#Window”).data(“tWindow”)将显示null。我已经从父页面或子页面中删除了jquery和javascript引用,

我有一个电传打字机从窗口弹出。它开得很好;但是,我在关闭窗口时遇到了一个问题。如果我向javascript、alert(“#Window”)或alert($(this).closest(“#Window”)添加一个警报,它将显示[object]。但是,alter(“#Window”).data(“tWindow”)或alert($(this).closest(“#Window”).data(“tWindow”)将显示null。我已经从父页面或子页面中删除了jquery和javascript引用,这没有任何区别。任何形式的帮助都将不胜感激。请参见下面的示例代码

以下是弹出窗口:

@{Html.Telerik().Window()
     .Name("Window")
     .Title("Student Window")
     .LoadContentFrom(Url.Action("AddReason", "Reason", new { id = reasonID }, Request.Url.Scheme))
     .ClientEvents(events => events
         .OnClose("ClosingWindow")
         )
     .Draggable(false)
     .Scrollable(false)
     .Width(800)
     .Height(600)
     .Modal(true)
     .Visible(false)
     //.Effects(fx => fx
     //    .Zoom()
     //    .Opacity())
     .Render();
 }
下面是JavaScript:

  <script src="@Url.Content("~/Scripts/jquery-1.4.4.js")" type="text/javascript">

</script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/spin.min.js")" type="text/javascript"></script>


function DoOpen(id) {
        var url = '@Url.Action("AddReason","Reason")';
        $.post(url, { id: id }, function (data) {
            var window = $('#Window').data('tWindow').center();
            window.content(data);
            window.open();
        });
   }
 //This javascript is in the main page
//I did an alert. alert($('#Window')) and 
alert($('#Window').data('tWindow')) they both return null

  function ClosingWindow() {
      $('#Window').prop("checked", "checked");
      $('#Window').data('tWindow').close();
       window.location.href = window.location.href;
   }

Here is the partial view :

    @model Student.Models.Reason
@using Student.Example

@{
    ViewBag.Title = "Add Reason";
    Layout = "~/Views/Shared/_PartialReason.cshtml";
}

<script type="text/javascript">
    function CloseWindow() {
//        alert($("#Window").closest('.t-window').data('#tWindow'));
//        $("#Window").data("tWindow").close();
        $('#Window').prop("checked", "checked");
         window.location.href = window.location.href;
    }

</script>

@using (Html.BeginForm("AddReason", "Reason", FormMethod.Post))
{
    @Html.ValidationSummary(true)
    <fieldset>
        <div class="editor-field">
            @(Html.Telerik().Editor()
            .Name("EncountersArchive")
            .HtmlAttributes(new { style = "height:310px;", id = "AddAReason" })
            .Encode(true)
            .Tools(
            tools => tools
                       .Clear()
                        .Bold().Italic().Underline().Strikethrough().Subscript().Superscript().Separator()
                        .FontName().FontSize()
                        .FontColor().BackColor().Separator()
                        .JustifyLeft().JustifyCenter().JustifyRight().JustifyFull().Separator()
                        .InsertUnorderedList().InsertOrderedList().Separator()
                        .Indent().Outdent().Separator()
            ))
        </div>
        <p style="text-align:center">

            <input type="submit" value="Reason" id="AddReasonID" onclick="CloseWindow()"/>
        </p>
    </fieldset>
}

函数DoOpen(id){
var url='@url.Action(“AddReason”,“Reason”);
$.post(url,{id:id},函数(数据){
var window=$('#window').data('tWindow').center();
窗口。内容(数据);
window.open();
});
}
//此javascript位于主页面中
//我发出了警报。警报($('#窗口'))和
警报($('#Window')。数据('tWindow'))它们都返回null
函数ClosingWindow(){
$(“#窗口”).prop(“选中”、“选中”);
$('#Window').data('tWindow').close();
window.location.href=window.location.href;
}
以下是局部视图:
@模范学生
@以学生为例
@{
ViewBag.Title=“添加原因”;
Layout=“~/Views/Shared/\u PartialReason.cshtml”;
}
函数CloseWindow(){
//警报($(“#窗口”)。最近(“.t窗口”)。数据(“#tWindow”);
//$(“#窗口”).data(“tWindow”).close();
$(“#窗口”).prop(“选中”、“选中”);
window.location.href=window.location.href;
}
@使用(Html.BeginForm(“AddReason”、“Reason”、FormMethod.Post))
{
@Html.ValidationSummary(true)
@(Html.Telerik().Editor())
.Name(“EncounterArchive”)
.HtmlAttributes(新的{style=“height:310px;”,id=“AddAReason”})
.Encode(真)
.工具(
工具=>工具
.Clear()
.Bold().Italic().Underline().删除线().Subscript().Superscript().Separator()
.FontName().FontSize()
.FontColor().BackColor().Separator()
.JustifyLeft().JustifyCenter().JustifRight().JustifyFull().Separator()
.InsertUnderedList().InsertOrderedList().Separator()
.Indent().Outdent().Separator()
))

}
弹出窗口上的OnClose事件导致该问题。仅当用户希望在窗口关闭后执行其他操作时,才应使用onclose事件。如果目的只是关闭窗口,Telerik控件将自动处理该窗口。在我的例子中,我只是删除onclose事件,它就像一个符咒