Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
588 views
in Technique[技术] by (71.8m points)

asp.net mvc - jqGrid dataUrl dropdown list not refreshing

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...