DevExpress MVC GridView刷新

时间:2014-10-11 13:05:48

标签: javascript asp.net-mvc devexpress devexpress-mvc

我需要在操作后在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()

1 个答案:

答案 0 :(得分:1)

首先,您应该编写window.gv_locations,然后确保包含js脚本的视图看到此网格(视图应包含网格和脚本)。如果有效,请给我回复。