3
我需要在操作後刷新ajax成功函數中的DevExpress GridView。我正在使用gridName.Refresh()
方法,但JavaScript正在拋出「udefined不是函數」錯誤。但是當我將這種方法寫入Google Chrome控制檯窗口時,它工作正常。問題是什麼?另外我的javascript代碼是在不同的JavaScript文件中,而不是在html代碼中。DevExpress MVC GridView刷新
這是我的jQuery的AJAX代碼,在分隔javascript文件
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()
我想你應該顯示一些代碼。 – Zabavsky 2014-10-11 13:22:18
我寫了我的代碼作爲答案。因爲我的代碼太長,不適合在這裏:) – 2014-10-13 08:39:43
沒有人回答我? – 2014-10-16 10:55:25