10

Is there anyway to disable the cache when using Ajax.ActionLink. Im having problems in IE whereby If I remove an item, which uses an ajax actionlink, it then reloads the partial view which the item is contained, and the item re-appears there (even tho it has been removed) On other browser's it works fine and as intended

   @Ajax.ActionLink("x", "RemoveItem", new { id = item.QuoteLineID, enquiryId = item.EnquiryID }, new AjaxOptions()
   {
       InsertionMode = InsertionMode.Replace,
       UpdateTargetId = "Summary"
   }, new { @class = "delete-link" })
2

3 Answers 3

12
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
public ActionResult RemoveItem(int id, int enquiryId)
{
    ...
}

or append a random parameter to the request using the routeValues argument.

5
  • This doesnt work, I've tried it, seems to be related to just IE
    – CallumVass
    Commented Jan 27, 2012 at 10:01
  • @BiffBaffBoff, then try appending a random number as an additional query string parameter when generating the link. Commented Jan 27, 2012 at 10:04
  • 1
    I solved it, I used HttpMethod = "POST" in the AjaxOptions. Seems to have done the trick
    – CallumVass
    Commented Jan 27, 2012 at 10:09
  • I wonder if one has to add this cruft to every ajax action now, to solve the issue... Commented Apr 14, 2015 at 0:52
  • @DarinDimitrov I used this but it's not working on Windows Safari 5.1.7 and Mac Safari also. Can you please help me in this. Commented Feb 8, 2016 at 8:35
7

I know you said you solved it by using HttpPost, but just in case that doesn't end up being the preferred solution, this works for me;

public ActionResult MyAction(string param1)
{
     Response.CacheControl = "no-cache";
     ...
}
0
3

I solved my problem by using :

<script type="text/javascript">
    $(document).ready(function () {
        // Disable browser cache Ajax.ActionLinks
        $.ajaxSetup({ cache: false });
    });
</script>

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.