MVC局部视图模型不刷新 [英] MVC Partial View Model Not Refreshing

查看:361
本文介绍了MVC局部视图模型不刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个局部视图,该视图正在asp.net MVC 3中加载到jQuery模态中.问题在于该视图未正确刷新.这是事件的顺序:

I have a partial view which is being loaded into an jQuery modal in asp.net MVC 3. The problem is that the view is not refreshing properly. Here is the order of events:

1)主视图有一个列出不同事件记录的表.表格的每一行上都有一个链接,用于显示事件详细信息. 2)单击此表上的链接时,部分视图将加载到模态中.

1) The main view has a table listing different events records. There is a link on each row of the table to show the event detail. 2) When the link on this table is clicked, the partial view is loaded in the modal.

在某些情况下,此方法运行良好,在其他情况下,该模型将花费很长时间加载.关闭局部视图/模态并单击主视图中表格上的另一个链接后,局部视图将加载,显示上一次加载的数据.它无法正确刷新.

This works fine in some cases, in other cases the model will take very long to load. After closing the partial view/modal and clicking on another link from the table on the main view, the partial view will load showing the data from the previous load. It is not refreshing correctly.

主视图上模态的定义: 加载请稍候...

Definition of Modal on Main View: Loading, please wait...

<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 上的控制器操作,以禁用缓存.

Use the OutputCacheAttribute on your controller action to disable caching.

[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
public PartialViewResult EventRegistrantSummary(Guid id)
{
    ModelState.Clear();
    Event e = db.Events.Single(ev => ev.ID == id);
    return PartialView(e);
}

这篇关于MVC局部视图模型不刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆