我需要在操作后刷新ajax成功函数中的DevExpress GridView。我正在使用gridName.Refresh()
方法,但 javascript 抛出“udefined is not a function”错误。但是当我将此方法写入 Google Chrome 控制台窗口时,它工作正常。问题是什么?此外,我的 javascript 代码位于不同的 JavaScript 文件中,而不是 html 代码中。
这是我在单独的 javascript 文件中的 jquery ajax 代码
function sendToMethod(url) {
$.ajax({
type: 'GET',
url: url,
contentType: 'application/html; charset=utf-8',
datatype: 'html'
})
.success(function (result) {
onCloseClick();
gv_locations.UnselectRows();//gv_locations is not defined
gv_locations.Refresh();//there is the same error here too
})
.error(function (result) {
});
}
这是我的 GridViewPartial.cshtml 文件
@Html.DevExpress().GridView(g =>
{
g.Name = "gv_locations";
g.KeyFieldName = "PublicIP";
g.SettingsPager.PageSize = 21;
g.Width = System.Web.UI.WebControls.Unit.Percentage(100);
g.ClientSideEvents.SelectionChanged = "onGridSelectionChanged";
g.SettingsEditing.Mode = GridViewEditingMode.EditFormAndDisplayRow;
g.CommandColumn.Visible = true;
g.Settings.ShowGroupPanel = true;
g.CommandColumn.ShowEditButton = true;
g.CommandColumn.ShowDeleteButton = true;
g.CommandColumn.ShowSelectCheckbox = true;
g.SettingsBehavior.AllowFocusedRow = true;
g.CallbackRouteValues = new { Controller = "Location", Action = "LocationGridViewPartial", id = ViewBag.Type };
g.SettingsEditing.UpdateRowRouteValues = new { Controller = "Location", Action = "LocationGridViewInlineUpdate" };
g.SettingsEditing.DeleteRowRouteValues = new { Controller = "Location", Action = "LocationGridViewInlineDelete" };
g.Columns.Add(column =>
{
column.Caption = "Client";
column.FieldName = "ClientID";
column.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.False;
});
g.Columns.Add(column =>
{
column.Caption = "IP";
column.FieldName = "PublicIP";
column.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.False;
});
g.Columns.Add("PublicIPName", "Lokasyon Adı");
g.Columns.Add(column =>
{
column.Caption = "Konum Tipi";
column.FieldName = "SelectedLocationTypeID";
column.ColumnType = MVCxGridViewColumnType.ComboBox;
var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
comboBoxProperties.DataSource = AtomicAdminPanel.Models.External.Location.LocationDataProvider.GetLocationTypes();
comboBoxProperties.TextField = "SelectedLocationTypeName";
comboBoxProperties.ValueField = "SelectedLocationTypeID";
});
g.Columns.Add(column =>
{
column.Caption = "Oluşturan";
column.FieldName = "CreatedUser";
column.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.False;
});
g.Columns.Add(column =>
{
column.Caption = "Oluşturma Tarihi";
column.FieldName = "CreatedDateTime";
column.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.False;
});
g.Columns.Add(column =>
{
column.Caption = "Değiştiren";
column.FieldName = "ChangedUser";
column.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.False;
});
g.Columns.Add(column =>
{
column.Caption = "Değiştime Tarihi";
column.FieldName = "ChangedDateTime";
column.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.False;
});
g.Columns.Add("IsActive", "Aktif", MVCxGridViewColumnType.CheckBox);
MVCxGridViewColumn col_listType = new MVCxGridViewColumn("LocationListType");
col_listType.Visible = false;
if (ViewBag.Id == "Online")
{
MVCxGridViewColumn col_online = new MVCxGridViewColumn("IsOnline", "Çevrimiçi", MVCxGridViewColumnType.Image);
col_online.SetDataItemTemplateContent(c =>
{
ViewContext.Writer.Write("<img src='../../Content/Image/statusOnline.png'/>");
});
g.Columns.Add(col_online);
}
}).Bind(Model).GetHtml()