私は、Telerik MVC 拡張機能を初めて使用します。ビューに最初のインスタンスを正常に実装しました。Telerik MVC Grid を使用して 2 番目のビューを実装していませんが、グリッドにバインドされているクラスには Nullable 型の 2 つの列があります。コードを実行すると、ビューは次のようなエラーを吐き出します。
ディクショナリに渡されたモデル アイテムは null ですが、このディクショナリには 'System.DateTime' 型の null 以外のモデル アイテムが必要です。
当初、これは DateTime のみで機能し、Nullable では機能しないテンプレートのレンダリングの問題であると考えていましたが、これらの DataTime を表示する列を完全に削除しましたか? プロパティ。
私のコードは次のとおりです。
Telerik MVC Grid のコードを表示する
<%= 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; }
}
どうすればこれを解決できるか考えている人はいますか?