0

I have an asp.net-mvc site and Iam using jqgrid, and I have a few fields where the edit control is a dropdown. I have an issue where the name int the dropdown is dependent comes from another column so I need to force a refresh from the server every time I bring up the edit form or if I click on the "+" to add a new entry to make sure the correct string is being shown.

I am seeing an issue where Internet Explorer seems to cache my dropdown list even if i try very hard to tell it not to. I don't observe the issue in Firefox or Chrome.

Here is my code:

The Col MODEL row that I a am observing the issue:

     { name: "SiteSettings", index: "SiteSettings", width: 250, editable: true, 
      edittype: "select", editoptions: { dataUrl: "/SiteSettings/GetSelectData" }, 
      editrules: { edithidden: true, required: false} },

And here is the code to construct the edit button and add button

    onClickButton: function () {
        jQuery("#grid").jqGrid('editGridRow', "new", { recreateForm: true, url: '/MyController/Add', afterSubmit: function (response, postdata) {
            var responseJson = $.parseJSON(response.responseText);
            return HandleJqGridAddResponse(responseJson);
        }, height: 380, width: "auto", closeAfterAdd: true, reloadAfterSubmit: true
        });
    },

        jQuery("#grid").jqGrid('editGridRow', id,
                    { url: '/MyController/Update', afterSubmit: function (response, postdata) {
                        var responseJson = $.parseJSON(response.responseText);
                        return HandleJqGridResponse(responseJson);
                    },
                        height: 380, width: "auto", recreateForm: true, closeAfterEdit: true,
                        closeOnEscape: true, reloadAfterSubmit: true
                    });

I thought

  recreateForm: true

or

  $("#grid").jqGrid({
     ajaxSelectOptions: { cache: false }
  });

would do the trick but it doesn't seem to make any difference.

but I have observed that when I bring up the edit form or the new form, that the function on my backend is NOT being called to return the list of items for the dropdown so there must be some client side caching.

How can I force a refresh of the dataurl (dataUrl: "/SiteSettings/GetSelectData") each time i try to edit or add a new entry?

leora
  • 188,729
  • 360
  • 878
  • 1,366
  • Ie is known for caching that kind of requests. Add an [OutputCache(duration=0)] on the action in your mvc controller. That forces ie to refresh – thsorens Sep 14 '14 at 17:10

2 Answers2

1

jQuery.extend(jQuery.jgrid.edit, {recreateForm: true}); Should work for you on the client side

To insure that there is no caching neither on the server side not on the client you could decorate the action that retrieves the data with [OutputCache(NoStore = true)] attribute

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

I think that the bast way is setting corresponding HTTP headers on the server side in the code which handle dataUrl ("/SiteSettings/GetSelectData"). I personally would includes the line

HttpContext.Current.Response.Cache.SetMaxAge (new TimeSpan (0));

or

Response.Cache.SetCacheability (HttpCacheability.ServerAndPrivate);
Response.Cache.SetMaxAge (new TimeSpan (0));

as the first line/lines of GetSelectData action. It will set Cache-Control: private, max-age=0 header (see here) and you will be sure that no web browser or web proxy will cache the server response.

If you prefer declarative setting of cache options you can use

[OutputCache(Duration = 0)]

or

[OutputCache(Duration = 0, Location = OutputCacheLocation.Client, VaryByParam = "*")]

I'm not sure which settings are the best, but the goal would be to set Cache-Control: private, max-age=0 header.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798