Thursday, June 8, 2017

MVC Caching issue

Issue:

I had an issue with a MVC view rendering a modal page.  The problem was that the AJAX call was not refreshing the view when it was re-rendered on the page.  The change to the database is occurring but the view refresh was not showing the latest information.

 var data = { "claimNumber": activeClaimID };
        $.ajax
        (
                 {
                     url: '@Url.Action("IndexPartial", "CaseFileViewModels")',
                     async: false,
                     type: 'GET',
                     data: data,
                     success: function (result) {

                         hideWaitDialog();
                       
                         //Clear out the entire modal block
                         $('#modal-container').empty();
                         $('#modal-container').append(result);
                         ret = true;
                     },
                     error: function (xhr, status, err) {
                         alert(xhr.responseText);
                         alert(status);
                     },
                 }
         );


My problem was that I did not assign the attribute Output Cache to the ActionResult.
Once I disabled the default hander on ActionResult then my view began to refresh.

[OutputCache(Location = System.Web.UI.OutputCacheLocation.None)]
public ActionResult IndexPartial()
{....}


Source:

https://stackoverflow.com/questions/20917398/view-not-refreshing-after-ajax-call


No comments:

Post a Comment