2014-03-25 53 views
4

我在我的MVC項目上使用Kendo窗口。

這是我從視圖Kendo UI窗口 - 防止加載以前的內容

@(Html.Kendo().Window() 
    .Name("window") 
    .Content("loading page..") 
    .Iframe(true) 
    .Draggable() 
    .Visible(false) 
    .Height(200) 
    .Width(400) 
    .Modal(true) 
) 



發起的對象,這是我如何調用使用JavaScript中的窗口,_url是動態

$('#window') 
    .data("kendoWindow") 
    .title("Add new category") 
    .refresh({ 
     url: _url 
    }) 
    .center() 
    .open(); 


我的問題是每當我第二次打開窗口,它仍然顯示以前的內容,直到它完成加載當前。

我會先嚐試隱藏使用此內容:

$('#window') 
    .kendoWindow({ 
     visible: false 
    }) 
    .data("kendoWindow") 
    .title("Add new category") 
    .refresh({ 
     url: _url 
    }) 
    .center() 
    .open(); 

但對象似乎被毀壞了,當我嘗試關閉它。

回答

12

使用此:

$('#window') 
    .data("kendoWindow") 
    .title("Add new category") 
    .content("") //this little thing does magic 
    .refresh({ 
     url: _url 
    }) 
    .center() 
    .open(); 

我不過建議你重新排列你的電話:

$('#window') 
    .data("kendoWindow") 
    .title("Add new category") 
    //.content("") //this little thing does magic 
    .content("<img src='ajax-loader.gif' alt='Loading...'/>") 
    .center() 
    .open(); 
    .refresh({ 
     url: _url 
    }) 

使用第二配置,並且提供了一個有效的加載圖片時,用戶會看到你的窗口,並通知內容正在被加載。這是非常有用的(更不用說用戶友好),因爲當您使用refresh函數時,Kendo窗口發出AJAX請求。

或者,您可以在窗口close事件中添加事件,並在處理程序中設置content("")

0

你也可能要添加

.Events(e => 
{ 
    e.Refresh("onRefresh"); 
}) 

<script> 
    function onRefresh() { 
     this.center(); 
    } 
<script> 

保持內容後爲中心的窗口,因爲它是異步加載被加載。

(如果您的內容高度可變)