0

I have dilaog box which loads data in success function of an ajax call as follows.

 $.ajax({

                url: '@Url.Action("GetPolicyPremiumAllocation", "Policy")',
                data: { policyID: selPolicyId },

                type: 'POST',
                success: function (data) {

                    if (data.length > 0) {
                        alert(data);
                        document.getElementById("modal_dialog").innerHTML = "";                        

                       // $("#modal_dialog").empty();
                        $("#modal_dialog").load(data,function( ) { 
                            $("#close-button-id").on("click", CloseDialog);
                        });
                        $("#modal_dialog").dialog("open");                                             
                         }
                }                   

            });

First time the div of dilaog is loading correct data.But Second time,it just shows the old data. I have tried to clear cache in the index action of my controller.Unable to figure out how to solve this.Please help.

hutchonoid
  • 32,982
  • 15
  • 99
  • 104
user1595214
  • 521
  • 3
  • 10
  • 22
  • I'm smelling Internet Explorer. It has an aggressive caching protocol. Did you test it in other browsers as well? Have a look at [this answer](http://stackoverflow.com/questions/10011780/prevent-caching-in-asp-net-mvc-for-specific-actions-using-an-attribute). – Andrei V May 27 '15 at 12:11
  • Set Cache: false and see if that works – dansasu11 May 27 '15 at 12:22

1 Answers1

0

Set ajax cache option to false:

 $.ajax({

            url: '@Url.Action("GetPolicyPremiumAllocation", "Policy")',
            data: { policyID: selPolicyId },
            cache:false,

            type: 'POST',
            success: function (data) {

                if (data.length > 0) {
                    alert(data);
                    document.getElementById("modal_dialog").innerHTML = "";                        

                   // $("#modal_dialog").empty();
                    $("#modal_dialog").load(data,function( ) { 
                        $("#close-button-id").on("click", CloseDialog);
                    });
                    $("#modal_dialog").dialog("open");                                             
                     }
            }                   

        });

Or decorate your Action with [OutputCache(NoStore = true, Duration = 0)]

Alex Art.
  • 8,711
  • 3
  • 29
  • 47