I am having problems with partial views being cached that I do not want to be. I have googled this and there are several ways around this, none of which seem to work for me.
Basically I have an action on the server that returns a partial view. I call it firstly from the Html.RenderPartial on page load. And then all the other calls are from jQuery on the same page, when links are clicked, which then refresh the section of the page the partial view is on.Each link that is pressed sends different data, so teh first time each link is clicked it calls teh server, but every subsequent click is rendered from a cached copy.
On my _Layout page (my master page) I have the following at teh top:
<script type="text/javascript">
$.ajaxSetup({
cache: false
});
</script>
And each ajax call has the cache disabled like this:
$.ajax({
url: UrlToGetEmployeeGrid,
type: 'GET',
cache: 'false',
success: function (response) {
$EmployeeGridObject.html(response);
},
error: function (xhr) {
alert('There was an error contacting the server to refresh the employee grid');
}
});
It is never reaching the server for the calls. But I also tried to add (just in case) the following to the controller action:
[HttpGet]
[OutputCache(Duration = 0)]
But this gives me an error:
System.InvalidOperationException: Duration must be a positive number.
I also tried:
[HttpGet]
[OutputCache(Duration = 0, VaryByParam="none")]
And got the same error.
Any ideas how I can stop caching from ajax calls to an action properly?
UPDATE:
Following on from Paulo's comment, this works fine in Chrome, but doesn't work in IE. I have added a random number to get around this issue for this one particular case. However, long term I need a better solution, as there will be cases where I need to cache actions for a time, that IE would need to be able to do.