.Net Cannot Model Bind DateTime from Grid

4 posts, 0 answers
  1. Nicholas
    Nicholas avatar
    8 posts
    Member since:
    Nov 2011

    Posted 11 Jul 2013 Link to this post

    I have a Grid for a strongly typed model with a DateTime property CreateDate.
    Html.Kendo().Grid<Department>()
    When editing a row, it posts the DateTime back to the server in the following format:
    CreateDate:Thu Jul 11 2013 11:54:13 GMT-0500 (Central Daylight Time)
    It posts to the following Controller action:
    public ActionResult UpdateDepartment([DataSourceRequest] DataSourceRequest request, Department department)

    .Net automatically binds the other values sent across, but if fails when parsing the CreateDate with the following message:

    The value 'Mon Jul 08 2013 08:50:16 GMT-0500 (Central Daylight Time)' is not valid for CreateDate.

    My culture is the default en-US.

    I found a forum post where someone has a similar issue. (http://www.kendoui.com/forums/kendo-ui-framework/globalization/datasource-date-format-incompatibile-with-asp-net-mvc-date-format.aspx#Z6fZydEt5E63AuZr05gjLQ)

    Is there a solution that allows Kendo and .Net to automatically bind the model?

    I have a workaround, and I realize I could use a custom model binder. However, both solutions are less than optimal.
  2. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2194 posts

    Posted 15 Jul 2013 Link to this post

    Hi Nicholas,

     
    From the provided information it seems that you missed to add the "kendo.aspnetmvc" script to the project which automatically convert the dates in way that can be understand by the MVC controller. More information about the required scripts can be found in this article. 

    Kind Regards,
    Vladimir Iliev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Nicholas
    Nicholas avatar
    8 posts
    Member since:
    Nov 2011

    Posted 15 Jul 2013 Link to this post

    Thanks, Vladimir.

    I was missing the kendo.aspnetmvc. That was a big help. However, I also noticed that if I set a custom parameter map, it removes the parameter map from the kendo.aspnetmvc script. Is there a way to add a custom Parameter map (from javascript) and keep the kendo.aspnetmvc script funcitonality?

    var grid = $("#DepartmentGrid").data("kendoGrid");
    grid.dataSource.transport.parameterMap = DepartmentGridParameterMap;

    Thanks,
    Nick
  4. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2194 posts

    Posted 17 Jul 2013 Link to this post

    Hi Nicholas,

     
    This feature is not supported out-of-the-box and it will require custom solution. I would suggest to get the unminified version of the aspnetmvc script and extend the parameter map with your custom code. 

    Kind Regards,
    Vladimir Iliev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top