2

I have a Kendo UI Grid with asp.net mvc syntax. I have a column with a datetime along with a editor template for edits. When I click edit it shows the datetimepicker but I'm unsure how to keep the current value (InvoicedDate) if one is already present. Any ideas?

Edit: When I select a date, it doesn't pull back that value into the update action either. I assume the issues are related.

Invoice Grid:

@(Html.Kendo().Grid<TMS.MVC.TIMS.Models.Invoice.InvoiceGridModel>()
<snip>
 columns.Bound(o => o.InvoicedDate).Width(100).Title("Invoice Date").Format("{0:M/d/yyyy}").EditorTemplateName("Invoice_InvoiceDate");
<snip>

Editor Template (Invoice_InvoiceDate.cshtml):

@model TMS.MVC.TIMS.Models.Invoice.InvoiceGridModel

   @(Html.Kendo().DateTimePicker()
                    .Name("InvoiceDate")
                    .Value(Model == null ? DateTime.Now : Model.InvoicedDate)
                    .Format("M/d/yyyy h:mm tt")
   )
Elim99
  • 663
  • 3
  • 17
  • 34

1 Answers1

5

I believe your problem is that your editorTemplate is attempting to take in

@model TMS.MVC.TIMS.Models.Invoice.InvoiceGridModel

This won't work because the column of the grid that you're calling the editorTemplate for is likely of Type DateTime. Since the types don't match you're always going to have null show up as the value of your model in the editor template. Try this instead.

@model DateTime? 
@(Html.Kendo().DateTimePicker()
                .Name("InvoiceDate")
                .Value(Model == null ? DateTime.Now : @Model)
                .Format("M/d/yyyy h:mm tt")
)
Shaun Poore
  • 612
  • 11
  • 23