Disable browser cache for ajax request on ASP.NET MVC

less than 1 minute read

The application reloads the list of jobs, if any job is reposted or expired. We display different labels, such as "reposted", "expired", depending on the action. It worked well with browsers but IE 8.

Simply, IE was cacheing the part of html. Though we request the partial view by post.

[sourcecode language="javascript"]
update: function () {
type: "GET",
url: "MJobsB?p=" + list.cPg(),
contentType: "text/html; charset=utf-8",
dataType: "html",
success: function (data) {
$('#ct #cnt').html(data);
error: function () { alert("Error Loading Jobs"); }

So, we brought in NoCache attribute. And made the action not cached on IE. We made it with attribute, as we want to cache other stuff, especially images.

This is NoCache attribute.

[sourcecode language="csharp"]
public class NoCacheAttribute : ActionFilterAttribute
public override void OnResultExecuting(ResultExecutingContext filterContext)


On controller, you just add the attribute.
[sourcecode language="csharp"]
public ActionResult MJobsB(int cId, int? pg)
return RenderJobListIn("_MJobsB", cId, Mode.List, pg, false);