Kendo UI MVC Grid DatePicker In-Line and In-Cell Edit Validation Error - The Value Is Not Valid

Errors:The value ‘Date Time’ is not valid for Field.

If you are using the Kendo UI MVC grid with in-line or in-cell editing and you are using a culture that does not format the dates with the month first (eg en-US) you might encounter the above error when you enter a date over the 12th day because it will try to save the day as the month.

After finding nothing on http://www.kendoui.com/documentation/asp-net-mvc/introduction.aspx I managed to find the answer by playing around with the examples files in the Q2'12 Beta solution.

  1. Get the culture code you require: eg en-AU for Australia from http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo(v=vs.71).aspx
  2. Add the following code to the section of your page layout and replace the culture code with your desired code. N.B. You will probably have to change the path to the script or remove the .min if you are not using the minified version of the scripts
<script src="@Url.Content("~/Scripts/cultures/kendo.culture.en-AU.min.js")"></script> <script type="text/javascript"> //set the Kendo UI culture kendo.culture("en-AU"); </script>

Do you agree with this solution? Do you know a better way? Please feel free to leave a comment and help us all in our quest for perfect code :-)

comments powered by Disqus