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

Grid does not display Datetime

1 Answer 193 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Martin Ennemoser
Top achievements
Rank 1
Martin Ennemoser asked on 25 Oct 2013, 08:53 AM
Hi,

I am unsing Kendo with MVC 5. I am binding my Grid over Ajax ( see attached project and code below). I receive the Date for the LastModified column
with the Json result but the date is not displayed. 
I have already made another project with kendo with a similar setup and everything worked perfectly

Hope you can help

@(Html.Kendo().Grid<Rainbow.ViewModels.CustomerViewModel>()
    .Name("CustomersGrid")
    .Events(events => events.DataBound("onDataBound").DataBinding("onDataBinding").DetailInit("onDetailInit"))
    .DataSource(d => d.Ajax().Read(r => r.Action("CustomersGridData", "Customer")))
    .Columns(c =>
    {
        c.Bound(i => i.Number).Title("Number");        
        c.Bound(i => i.LastModified).Title("LastModified");        
    })
    .Sortable()
    .Filterable()
    .Pageable())

1 Answer, 1 is accepted

Sort by
0
Ignacio
Top achievements
Rank 1
answered on 25 Oct 2013, 08:26 PM
This is a problem with the way regular MVC controllers serialize DateTimes.
{"lastModified":"\/Date(-62135578800000)\/"}
Which is different than the way ApiControllers do it
"lastModified": "2013-10-25T16:17:43.4521811-04:00"

You can read more about this problem here.
http://www.hanselman.com/blog/OnTheNightmareThatIsJSONDatesPlusJSONNETAndASPNETWebAPI.aspx

So your options are plenty.
  • Change the datetime to a string on your ViewModel
  • Change the way MVC serializes DateTimes (its a little tricky. See here)
  • Switch for a ApiController to return your GridData

Hope this helps
Tags
Grid
Asked by
Martin Ennemoser
Top achievements
Rank 1
Answers by
Ignacio
Top achievements
Rank 1
Share this question
or