'DataBinding:'System.Web.Mvc.SelectListItem'不包含名称为'Id'的属性。'

时间:2019-06-20 19:32:23

标签: c# model-view-controller kendo-ui-mvc

我不确定为什么在列表内找不到属性“ Id”。 ProductionLines定义为IEnumerable,ProductionLine定义为“ Id”属性。

我尝试将其保留为IEnumerable,并且我发现有时在两次定义SelectList时会发生这种情况,我不认为是这种情况。

@model SQDCDashboard.Core.ViewModels.SafetyIncidentIndexModel

@(Html.Kendo().Grid<SQDCDashboard.Core.ViewModels.SafetyIncidentViewModel>
    (Model.ListSafetyIncidents)

    .Name("safetyincident-grid")
    .Columns(columns =>
    {
        columns.Bound(c => c.CreatedAt).HtmlAttributes(new { style = "width: 22%" }).Format("{0:MM/dd/yyyy}");
        columns.Bound(c => c.Type).HtmlAttributes(new { style = "width: 22%" });
        columns.Bound(c => c.Description).HtmlAttributes(new { style = "width: 22%" });
        columns.ForeignKey(c => c.ProductionLineId, new SelectList(Model.ProductionLines.ToList()), "Id", "Name").HtmlAttributes(new { style = "width: 22%" });
        columns.Command(command => { command.Edit(); }).HtmlAttributes(new { style = "width: 12%" });
    })
    .ToolBar(toolbar => toolbar.Create())
    .Editable(editable => editable.Mode(GridEditMode.InLine))
    .DataSource(ds =>
    ds.Ajax()
    .ServerOperation(false)
    .Model(model => model.Id(p => p.Id))
    .Read(read => read.Action("GetSafetyIncidentList", "Safety"))
    .Update(update => update.Action("EditSafetyIncidentPopUp", "Safety"))
    .Create(update => update.Action("CreateNewSafetyIncident", "Safety"))
    )
    .HtmlAttributes(new { style = "height: 100%" })
    .Sortable()
    .Filterable()
)

我希望它在ProductionLine数据库中显示所有ProductionLine的名称。

0 个答案:

没有答案