我对 Telerik MVC 扩展相当陌生。我已经成功地在视图中实现了我的第一个实例。我没有使用 Telerik MVC Grid 实现我的第二个视图,但是绑定到网格的类有 2 个类型为 Nullable 的列。当我运行我的代码时,视图会显示如下错误:
传入字典的模型项为空,但此字典需要“System.DateTime”类型的非空模型项。
我最初认为这可能是一个仅适用于 DateTime 而不是 Nullable 的模板的渲染问题,但后来我完全取出了显示这些 DataTime 的任何列?特性。
我的代码如下:
查看 Telerik MVC 网格的代码
<%= Html.Telerik().Grid(Model.ScheduledCourseList)
.Name("ScheduledCoursesGrid")
.ToolBar(commands => commands.Insert().ButtonType(GridButtonType.Image).ImageHtmlAttributes(new { style = "margin-left:0" }))
.DataKeys(keys => keys.Add(sc => sc.Id))
.DataBinding(dataBinding =>
dataBinding.Ajax()
.Select("_List", "Course")
.Insert("_InsertAjax", "Course")
.Update("_UpdateAjax", "Course")
.Delete("_DeleteAjax", "Course")
)
.Columns(columns =>
{
columns.Bound(c => c.Id).Width(20);
//columns.Bound(c => c.ScheduledDateTime).Width(120);
//columns.Bound(c => c.Location).Width(150);
columns.Command(commands =>
{
commands.Edit().ButtonType(GridButtonType.Image);
commands.Delete().ButtonType(GridButtonType.Image);
}).Width(180).Title("Commands");
})
.Editable(editing => editing.Mode(GridEditMode.PopUp))
.Sortable()
.Footer(true) %>
DTO
public class ScheduledCourseDTO
{
public int Id { get; set; }
public int CourseId { get; set; }
public int CourseProviderId { get; set; }
public DateTime? ScheduledDateTime { get; set; }
public DateTime? EndDateTime { get; set; }
public string Location { get; set; }
public int SiteId { get; set; }
public decimal CostBase { get; set; }
public decimal CostPerAttendee { get; set; }
public decimal PricePerAttendee { get; set; }
public int MaxAttendees { get; set; }
public int CancellationDays { get; set; }
public bool Deleted { get; set; }
}
有人知道我该如何解决这个问题吗?