I am reasonably new to Telerik MVC extensions. I have implemented my first instance in a view successfully. I am not implementing my second view using the Telerik MVC Grid, however the class that is being bound to the grid has 2 columns which are of type Nullable. When I run my code, the view spits out an error as follows:
The model item passed into the dictionary is null, but this dictionary requires a non-null model item of type 'System.DateTime'.
I originally thought this might be a rendering problem with a template that only works with DateTime and not Nullable, but then I totally took out any columns displaying these DataTime? properties.
My code is as follows:
View code for 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; }
}
Does anybody have an idea how I can solve this?