1

I'm new to web development and working on my first ASP.NET MVC 3 app. I'm using jqGrid and noticed that refreshing the page does not refresh the values in the dropdownlist until I open the same page in another tab, then refreshing the first tab will pick up the changed values.

I've got a controller action that looks like this:

public JsonResult FavoriteToppings()
{
   var all = GetFavoriteToppings();
   return Json(all, JsonRequestBehavior.AllowGet);
}

and I've the part of the jqGrid definition looks like this:

{ name: 'ToppingID', index: 'ToppingID', width: 200,
    editable: true, align: 'left', edittype: 'select', stype: 'select',
    editoptions: {
        dataUrl: '@Url.Action("FavoriteToppings", "Dessert")',
        buildSelect: createSelectList
    },
    searchoptions: {
        dataUrl: '@Url.Action("FavoriteToppings", "Dessert")',
        buildSelect: createSelectList,
        sopt: ['eq']
    }
},

and createSelectList looks like this:

createSelectList = function (data) {
    var response, s = '<select>', i, l, ri;
    if (typeof (data) === "string") {
        //var leng = data.length - 1;
        response = jQuery.parseJSON(data);
    }
    else {
        response = jQuery.parseJSON(data.responseText);
        s += '<option value="">Select...</option>';
    }

    if (response && response.length) {
        for (i = 0, l = response.length; i < l; i += 1) {
            ri = response[i];
            s += '<option value="' + ri + '">' + ri + '</option>';
        }
    }
    return s + '</select>';
}

I noticed this when editing one of the topping names. I changed the misspelled "Hot Fugde" to "Hot Fudge" and saved that off. The underlying data in the table gets updated to show the correctly spelled topping (i.e., all the rows correctly reflect the change) when I refresh the page but the filter dropdown doesn't. That action isn't called at all after the first time to pick up the change.

When I do open the same page in a different page of the browser, then the action gets called. After that, refreshing the first tab will result in the correctly spelled entry showing up in the select list.

Perhaps I'm just going about this incorrectly. Any guidance?

itsmatt
  • 31,265
  • 10
  • 100
  • 164

2 Answers2

4

I think you have to use

ajaxSelectOptions: { cache: false }

jqGrid parameter to set additional parameter cache: false for the jQuery.ajax used by jqGrid if it get the data from the server from the dataUrl.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • @itsmatt: You are welcome! It's one from tem problems which solution is very simple, but for which one can spend many time. :-) – Oleg Sep 14 '11 at 20:18
1

I've noticed that cache policies vary from browser to browser (chrome seems to have the most aggressive caching policy). Does the behavior repeat in all browsers? Ctrl-F5 work?

Adam
  • 141
  • 8