【发布时间】:2015-01-06 22:55:54
【问题描述】:
我的 asp.net mvc 视图中有以下内容:-
<div class=" b" >Show @Html.DropDownList("type", new SelectList(ViewBag.type, "Value", "Text", "" ), new { @id= "typeOptions",@class="SmallDropDown3"}) Requestors.
<img src="~/Content/sortloading.gif" class="loadingimage" id="progressSort3" /></div>
@Html.Partial("_GetRequestors", Model)
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
<script>
$("body").on('change', '#typeOptions', function () {
$('#progressSort3').show();
$.ajax({
type: "Get",
url: '@Url.Action("GetRequestors","Customer")',
data: { id: "@ViewBag.AccountID", page: "1", type: $("#typeOptions").val() },
success: function (html) {
$('#RequestorTable').html(html);
$('#progressSort3').hide(); //This could also be dialog("open") depending on the version of jquery ui.
}
});
});
</script>
主要显示一个下拉菜单,当列表项发生变化时,它将启动一个 Ajax 调用。这是将被调用的操作方法:-
public ActionResult GetRequestors (int id = 0,int page=1,string type="")
{
int pagesize;
ViewBag.type = ViewBag.PagedSizeOptions = new PageOptions().RequestorTypeOptions;
bool succeed = int.TryParse(System.Web.Configuration.WebConfigurationManager.AppSettings["TechPageSize"], out pagesize);
var aUser = repository.populateRequestorDetials2(id,type).OrderBy(a=>a.FIRST_NAME).ToPagedList(page, pagesize);
ViewBag.AccountID = id;
ViewBag.currenttype = type;
if (Request.IsAjaxRequest())
{
return PartialView("_GetRequestors", aUser);
}
return View(aUser);
}
目前看来IE会长时间缓存结果,而且在更改dropdpwnlist时IE总是会显示同一个下拉项的缓存结果,即使硬刷新(ctrl-f5)也不会删除缓存结果... 所以我主要有这两个问题:-
IE 会将缓存数据保留多长时间?
我知道我可以添加 cache:false 作为 ajax 参数。但问题是如果我没有在我的 IE 的 Ajax 调用中指定任何缓存设置,那么默认行为是什么。在chrome和firefox中不会遇到缓存问题吗?
任何人都可以就这些问题提出建议吗?
谢谢。
【问题讨论】:
-
添加一个随机 uuid 作为 url get 参数怎么样?
-
使用 Razor,您应该使用您的操作方法上的各种属性在服务器端“修复”它。大多数 Ajax 解决方案不会针对服务器缓存要求进行微调(您可以对服务器进行更多控制)。
标签: jquery ajax asp.net-mvc caching razor