This is a migrated thread and some comments may be shown as answers.

Problem with nullable DateTime property

2 Answers 198 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ozzy Knox
Top achievements
Rank 1
Ozzy Knox asked on 17 Nov 2010, 07:17 PM

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?


2 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 18 Nov 2010, 08:24 AM
Hello Ozzy Knox,

 Please check this forum thread which describes how to deal with this problem.

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Ozzy Knox
Top achievements
Rank 1
answered on 18 Nov 2010, 08:57 AM
Thank you Atanas.

I actually did read the thread you mention in your answer prior to posting my question.  However, when I upgraded to the 2010 Q3 release, my project did not include the EditorTemplates folder inside Views/Shared, so this is why I didn't see the templates before.  I clicked on Show All Files in my Solution Explorer and have seen the EditorTemplates folder and can now make the change as described in the thread link you provided.  I have made the change as per that thread and it is now working.

Thanks for the prompt response.
Tags
Grid
Asked by
Ozzy Knox
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Ozzy Knox
Top achievements
Rank 1
Share this question
or