IE未更新Asp.Net MVC3部分视图

IE Not Updating Asp.Net MVC3 Partial View

本文关键字:视图 MVC3 Net 更新 Asp IE      更新时间:2023-09-26

我有一个页面,其中包含通过ajax请求返回的部分视图的div。

    $.ajax({
        url: 'CompleteSessions',
        success: function (data) {
            var selector = $('#complete-session-section');
            if (data.length > 0) {
                selector.html(data);
            }
            else {
                selector.append($(document.createElement('option')).html('No assessments'));
            }
        }
    });

分部视图本身有一个模型,并根据返回的会话数量构造一个组合框。

    @using SmartQWeb.Models.Entities
@using SmartQWeb.Runtime;
@model IEnumerable<Session>

<span class="dropdown">
<select style="width: 75%" id = "complete-session-selector">
    <option id="-1">Select a Session</option>
    @foreach (Session session in Model.OrderByDescending(date=>date.StartTime))
    {
        if (session.Assessment != null)
        {
            <option id="@session.AssessmentId" value="@session.Id" title="Administered by: @session.User.Name" data-assessmentId="@session.AssessmentId">@session.Participant.AliasLookup.AliasId - @session.StartTime  </option>
        }
    }
</select>

</span>

问题是,仅对于IE,在首次加载页面时,下拉列表不会得到正确更新。我必须点击F5(有时控制F5)来刷新并查看组合框中的新条目。这对Chrome或Firefox来说不是问题。

jQuery ajax请求的默认"type"参数是IE将缓存的"GET"。您可以在ajax请求中禁用缓存,或者切换到"POST"以防止这种情况发生——
$.ajax({
    ...
    cache: false
});