caching as might be expected is controlled the callee (controller) not the caller. an actionlink is just an anchor with a route path. in the controller method via caching attributes you control this.
but why post when you want a get? this will cause the browser to throw a repost message on a back navigation. also to combat common web coding errors most browsers will not cache a post, but some will. the proper way to control caching is with the cache
header, not some side effect.
bruce (sqlwork.com)
Marked as answer by ricka6 on Nov 01, 2011 02:26 AM
I don't belive by default browser will cache identic GET requests(Even if you run your sample, GET HTML, XHR requests will not cache by default). This is the excellent caching tutorial that tells how browser caching works.
http://www.mnot.net/cache_docs/
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
In my case Ajax.ActionLinks were being handled by the unobtrusive javascript support for jquery. To disable caching of the these links I just made a call to $.ajaxSetup({ cache: false });
Do a POST instead of GET in order to get the results. The browser caches identic GET requests (choose the HTTP method on the AjaxOptions paramter)
Radu, thanks a lot for the tip!
The cache of Ajax.ActionLink by IE8 has been a headache for a while. FF does not have this problem.
It is finally gone thanks to your tip. The only thing I did to resolve this is following your suggestion by adding "HttpMethod = "POST" to AjaxOptions.
rishialagesa...
Participant
789 Points
179 Posts
Disable cache in Ajax.ActionLink extension method in asp.net MVC
May 16, 2011 11:38 AM|LINK
How to disable cache in Ajax.ActionLink extension method. I want this link to return fresh data everytime i click on this link.
Thanks in advance.
Alagesan.
raduenuca
All-Star
24675 Points
4250 Posts
Re: Disable cache in Ajax.ActionLink extension method in asp.net MVC
May 16, 2011 12:28 PM|LINK
Do a POST instead of GET in order to get the results. The browser caches identic GET requests (choose the HTTP method on the AjaxOptions paramter)
Radu Enuca | Blog
bruce (sqlwo...
All-Star
36850 Points
5445 Posts
Re: Disable cache in Ajax.ActionLink extension method in asp.net MVC
May 16, 2011 03:20 PM|LINK
caching as might be expected is controlled the callee (controller) not the caller. an actionlink is just an anchor with a route path. in the controller method via caching attributes you control this.
note: you can not post with an actionlink.
raduenuca
All-Star
24675 Points
4250 Posts
Re: Disable cache in Ajax.ActionLink extension method in asp.net MVC
May 16, 2011 03:45 PM|LINK
We are talking about Ajax.ActionLink not Html.ActionLink
Try the following:
1.Create a default internet MVC3 application
2.In the HomeController add:
In Views\Shared folder add 2 partial views called _Test1.cshtml and _Test2.cshtml (with the following code):
In Views\Home\Index.cshtml append:
For me was necessary to add the following in Layout.cshtml:
to make it work.
Now run the project and start clicking the links and tell me which one gets updated....
Radu Enuca | Blog
bruce (sqlwo...
All-Star
36850 Points
5445 Posts
Re: Disable cache in Ajax.ActionLink extension method in asp.net MVC
May 16, 2011 04:21 PM|LINK
but why post when you want a get? this will cause the browser to throw a repost message on a back navigation. also to combat common web coding errors most browsers will not cache a post, but some will. the proper way to control caching is with the cache header, not some side effect.
imran_ku07
All-Star
45815 Points
7698 Posts
MVP
Re: Disable cache in Ajax.ActionLink extension method in asp.net MVC
May 16, 2011 05:52 PM|LINK
I don't belive by default browser will cache identic GET requests(Even if you run your sample, GET HTML, XHR requests will not cache by default). This is the excellent caching tutorial that tells how browser caching works.
http://www.mnot.net/cache_docs/
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD
Yarx
Member
18 Points
9 Posts
Re: Disable cache in Ajax.ActionLink extension method in asp.net MVC
Jun 15, 2011 03:16 PM|LINK
In my case Ajax.ActionLinks were being handled by the unobtrusive javascript support for jquery. To disable caching of the these links I just made a call to $.ajaxSetup({ cache: false });
zipswich
Member
271 Points
434 Posts
Re: Disable cache in Ajax.ActionLink extension method in asp.net MVC
Jun 30, 2011 09:34 PM|LINK
Radu, thanks a lot for the tip!
The cache of Ajax.ActionLink by IE8 has been a headache for a while. FF does not have this problem.
It is finally gone thanks to your tip. The only thing I did to resolve this is following your suggestion by adding "HttpMethod = "POST" to AjaxOptions.
JoeKahl
Member
6 Points
3 Posts
Re: Disable cache in Ajax.ActionLink extension method in asp.net MVC
Aug 01, 2012 03:51 PM|LINK
Perfect. Elegant. Simple.
<script type="text/javascript"> $(document).ready(function () { // Disable browser cache Ajax.ActionLinks $.ajaxSetup({ cache: false }); }); } //</script>Now I can click on the Ajax ActionLinks repeatedly. They were only responding to the first click until adding this change.
I apprecite your post.
Joe