我在讀取劍道網格數據時遇到了問題。 控制器拋出異常「找不到原始類型的公共屬性進行排序。」Kendo使用複雜對象進行網格排序
視圖模型
public class PatientModel : IMapFrom<Patient>, IHaveCustomMappings
{
public int? Id { get; set; }
public PersonalDataModel PersonalDataModel { get; set; }
}
控制器
public ActionResult EditingPopup_Read([DataSourceRequest] DataSourceRequest request)
{
var source = repository.All<PatientModel>();
var patients = repository.All<PatientModel>().ToDataSourceResult(request);
return Json(patients,JsonRequestBehavior.AllowGet);
}
查看
@(Html.Kendo().Grid<DentalSoft.Data.Contracts.Patientes.PatientModel>()
.Name("PatientsGrid")
.Columns(columns =>
{
columns.Bound(p => p.PersonalDataModel.FirstName).Filterable(ftb => ftb.Cell(cell => cell.ShowOperators(false)));
columns.Bound(p => p.PersonalDataModel.SecondName).Filterable(ftb => ftb.Cell(cell => cell.ShowOperators(false)));
columns.Bound(p => p.PersonalDataModel.LastName).Filterable(ftb => ftb.Cell(cell => cell.ShowOperators(false)));
columns.Bound(p => p.PersonalDataModel.TelephoneNumber).Filterable(ftb => ftb.Cell(cell => cell.ShowOperators(false)));
columns.Bound(p => p.PersonalDataModel.HealthStatus).Filterable(ftb => ftb.Cell(cell => cell.ShowOperators(false))).Width(200);
columns.Command(command => { command.Edit(); command.Destroy(); }).Width(250);
})
.Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("PatientModel"))
.ToolBar(toolbar => toolbar.Create())
.Scrollable()
.Sortable()
.Filterable(ftb => ftb.Mode(GridFilterMode.Row))
.HtmlAttributes(new { @class = "patients-grid" })
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Model(model => model.Id(p => p.Id))
.Create(create => create.Action("EditingPopup_Create", "Grid"))
.Read(read => read.Action("EditingPopup_Read", "Grid"))
.Update(update => update.Action("EditingPopup_Update", "Grid"))
.Destroy(destroy => destroy.Action("EditingPopup_Destroy", "Grid"))
)
.Selectable()
)
視圖模型將有更多3,4個複雜的對象。