添加后停止重新加载下拉列表 [英] stop reloading dropdowns after add

查看:131
本文介绍了添加后停止重新加载下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的下拉菜单的代码.

Here is the code of my dropdown.

  {
 name: 'ClassId', index: 'ClassId', align: 'center',editable: true, edittype: 'select',
 editoptions: {
 dataUrl:'@Url.Action("GetAllClasses", "Class", new { Area = "Curriculums"})',
 buildSelect: function (data) {
                     var response, s = '<select>', i;
                     response = jQuery.parseJSON(data);
                     //s += '<option value="0">--Select Class--</option>';
                     if (response && response.length) {
                         $.each(response, function (i) {
                      s += '<option value="' + this.Id + '">' + this.ClassName + '</option>';
                      });
                     }
                     return s + '</select>';
                 }
             }
          },

我正在使用表单编辑.插入后我正在重新加载网格.但是问题是当我尝试添加另一个时插入数据后,我的下拉列表被刷新了.我希望下拉选择的值将是先前选择的值.不想在第二次添加时更改下拉选择的值.

I am using form edit.I am reloading grid after insert.But the problem is after inserting data when I try to add another one my dropdowns are getting refreashed.I want that the dropdown selected value will be previously selected value.I don't want to change dropdown selected value on the second add.

推荐答案

防止从dataUrl重新加载数据的最简单方法是在服务器响应中设置Cache-Control HTTP标头.例如,在服务器响应中设置Cache-Control: max-age=60可以防止在60秒内从服务器重新加载数据.对于ASP.NET MVC,您可以使用例如CacheControl属性(请参阅DurationLocation属性).

The most simple way to prevent reloading of data from dataUrl could be setting Cache-Control HTTP header in the server response. Setting of Cache-Control: max-age=60 in the server response for example will prevent reloading of data from the server during 60 sec. In case of ASP.NET MVC you can use CacheControl attribute for example (see Duration and Location properties).

另一种选择是动态设置editoptions.value而不是用法editoptions.dataUrl.例如,可以包含构建editoptions.value所需的信息,以作为填充网格的服务器标准响应的扩展.可以使用beforeProcessing处理部分数据.您将在以下冷答案中找到相应的示例:这一个这一个和其他. 答案简要描述了创建完整动态网格的一种可能情况.

One more alternative would be dynamical setting editoptions.value instead of usage editoptions.dataUrl. For example one can include the information needed for building editoptions.value as an extension of the standard response of the server for filling the grid. One can use beforeProcessing to process the part of the data. You will find the corresponding examples in the following cold answers: this one, this one, this one, this one, this one and other. The answer describes in short one of the the possible scenario to create full dynamic grid.

这篇关于添加后停止重新加载下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆