This is a migrated thread and some comments may be shown as answers.
.Net Cannot Model Bind DateTime from Grid
5 Answers 45 Views
This is a migrated thread and some comments may be shown as answers.
Nicholas
Top achievements
Rank 1
Nicholas asked on 11 Jul 2013, 07:07 PM
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.

5 Answers, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 15 Jul 2013, 08:23 AM
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!
0
Nicholas
Top achievements
Rank 1
answered on 15 Jul 2013, 01:45 PM
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
0
Vladimir Iliev
Telerik team
answered on 17 Jul 2013, 08:29 AM
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!
0
Janet
Top achievements
Rank 1
answered on 08 May 2020, 06:00 AM

Hi support, I have same issue, but not sure how to use the "kendo.aspnetmvc" ?  

Currently I have to use parameterMap explicetely for each date field, but it feels wrong

 

parameterMap: function (data, type) {
    if (type != "read"){
        data.CreateDate = data.CreateDate.toISOString();
    }
    return data;
}

 

0
Ivan Danchev
Telerik team
answered on 11 May 2020, 04:58 PM

Hello Janet,

The kendo.aspnetmvc is a script that can be loaded along with kendo.all:

<script src="https://kendo.cdn.telerik.com/2020.1.406/js/jquery.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2020.1.406/js/kendo.all.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2020.1.406/js/kendo.aspnetmvc.min.js"></script>

Regards,
Ivan Danchev
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
Grid
Asked by
Nicholas
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Nicholas
Top achievements
Rank 1
Janet
Top achievements
Rank 1
Ivan Danchev
Telerik team
Share this question
or