我有一个包含以下代码的patial视图(使用自定义数据绑定):
部分视图
@{
Html.EnableClientValidation();
Html.EnableUnobtrusiveJavaScript();
var grid = Html.DevExpress().GridView(settings => {
settings.Name = "GridView1";
settings.KeyFieldName = "StudentId";
settings.CallbackRouteValues = new { Controller = "CustomBinding", Action = "MyGridViewPartial" };
settings.CustomActionRouteValues = new { Controller = "Editing", Action = "ChangeEditModePartial" };
settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "CustomBinding", Action = "GridView1PartialAddNew" };
settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "CustomBinding", Action = "GridView1PartialUpdate" };
settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "CustomBinding", Action = "GridView1PartialDelete" };
settings.SettingsEditing.Mode = GridViewEditingMode.EditFormAndDisplayRow;
settings.SettingsBehavior.ConfirmDelete = true;
settings.SettingsPopup.EditForm.Width = 600;
settings.CommandColumn.Visible = true;
settings.CommandColumn.ShowNewButton = true;
settings.CommandColumn.ShowDeleteButton = true;
settings.CommandColumn.ShowEditButton = true;
settings.CustomBindingRouteValuesCollection.Add(
GridViewOperationType.Paging,
new { Controller = "MyController", Action = "MyPagingAction" }
);
settings.CustomBindingRouteValuesCollection.Add(
GridViewOperationType.Sorting,
new { Controller = "MyController", Action = "MySortingAction" }
);
settings.SettingsAdaptivity.AdaptivityMode = GridViewAdaptivityMode.Off;
settings.SettingsAdaptivity.AdaptiveColumnPosition = GridViewAdaptiveColumnPosition.Left;
settings.SettingsAdaptivity.AdaptiveDetailColumnCount = 1;
settings.SettingsAdaptivity.AllowOnlyOneAdaptiveDetailExpanded = false;
settings.SettingsAdaptivity.HideDataCellsAtWindowInnerWidth = 0;
settings.Columns.Add("StudentId");
settings.Columns.Add("StudentName");
settings.Columns.Add("StudentAge");
settings.Columns.Add("StudentGrade");
settings.Columns.Add("StudentAddress");
settings.PreRender = (sender, e) =>
{
((MVCxGridView)sender).StartEdit(0);/**//This is the Exception line**
};
settings.CellEditorInitialize = (s, e) =>
{
ASPxEdit editor = (ASPxEdit)e.Editor;
editor.ValidationSettings.Display = Display.Dynamic;
};
});
if (ViewData["EditError"] != null){
grid.SetEditErrorText((string)ViewData["EditError"]);
}
}
@grid.BindToCustomData(Model).GetHtml()///Custom binding
请建议解决方案:
异常: 在基础数据源中找不到通过KeyFieldName属性指定的主键字段。确保字段名称拼写正确。注意角色案例。
答案 0 :(得分:-1)
您确定模型包含(StudentId)属性,并且您已成功从db中检索它,并且它是公共的getter和setter