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?
See Question&Answers more detail:os