我有一個部分視圖,它正在加載到asp.net MVC 3中的jQuery模態。問題是視圖不能正確刷新。這裏是事件的順序:MVC部分視圖模型不刷新
1)主視圖有一個表列出不同的事件記錄。表格的每一行都有一個鏈接來顯示事件的詳細信息。 2)當點擊該表上的鏈接時,局部視圖將加載到模態中。
這在某些情況下可以正常工作,但在其他情況下,該模型需要很長時間才能加載。在關閉局部視圖/模態並單擊主視圖中的表格中的另一個鏈接後,局部視圖將加載顯示前一個加載的數據。它不正確刷新。在主視圖模態的
定義: 加載中,請稍候......
<script type="text/javascript">
$(document).ready(function() {
$("#EventRegistrantSummary").dialog({
bgiframe: true, autoOpen: false, height: 500, width: 980, resizable: false, modal: true
});
});
function showEventRegistrantSummary(id) {
$.get("/Event/EventRegistrantSummary/" + id, function (data) {
$("#EventRegistrantSummary").html(data);
});
$("#EventRegistrantSummary").dialog('open'); return false;
}
</script>
控制器:
public PartialViewResult EventRegistrantSummary(Guid id)
{
ModelState.Clear();
Event e = db.Events.Single(ev => ev.ID == id);
return PartialView(e);
}
管窺:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<model.Event>" %>
<% using (Ajax.BeginForm("EditUpdate", new AjaxOptions { UpdateTargetId="Target", InsertionMode= InsertionMode.Replace}))
{%>
<h6 style="text-align:center">Registration Summary: <%= Model.Name %></h6>
<div style="float:left;width:35%">
<fieldset id="Overview">
<legend>Overview</legend>
<div class="editor-label">
Total Registrants: <%= Model.BoatEventRegistrations.Count() %>
</div>
</fieldset>
</div>
<% } %>
任何幫助,非常感謝。
您知道使用此方法與使用控制器上的OutputCacheAttribute控制服務器上的緩存有什麼好處嗎? –
如果您對多個操作使用共享的ajax調用,或者有很多方法需要避免緩存。由於提供了控件,我們通過jQuery處理大約95%的所有表單帖子。 – Henry