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

Date issue

0 Answers 56 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ankit
Top achievements
Rank 1
ankit asked on 25 Jun 2013, 03:10 AM
Hi there

We are using license version of KendoUI version 2012.2.913.340.
It's MVC 4 in .Net 4.5.

I have a grid on a page and it has CRUD on controller. I do get data on grid as a search result.

When I edit one of the record and try to save, I get issue on date as I see date coming to controller is : 1/01/0001 12:00:00 AM. I tried to put following code to see what the issue is and I can see issue is on line 16 where Attempted value is 6/25/2013 10:45:00 AM in place of 25/6/2013 10:45:00 AM.

FYI,
I do have web.config set to following:
1.<globalization culture="en-AU" uiCulture="en-AU" />
I have tried using Code first 5.0 as well as EDMX (default)
01.public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
02.        {
03. 
04. 
05.            var displayFormat = bindingContext.ModelMetadata.DisplayFormatString;
06.            var value = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
07. 
08.            if (!string.IsNullOrEmpty(displayFormat) && value != null)
09.            {
10.                DateTime date;
11.                displayFormat = displayFormat.Replace("{0:", string.Empty).Replace("}", string.Empty);
12.                // use the format specified in the DisplayFormat attribute to parse the date
13. 
14.                bindingContext.ModelState.SetModelValue(bindingContext.ModelName, bindingContext.ValueProvider.GetValue(bindingContext.ModelName));
15. 
16.                if (DateTime.TryParseExact(value.AttemptedValue, displayFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out date))
17.                {
18.                    return date;
19.                }
20.                else
21.                {
22.                    bindingContext.ModelState.AddModelError(
23.                        bindingContext.ModelName,
24.                        string.Format("{0} is an invalid date format", value.AttemptedValue)
25.                    );
26.                }
27.            }
28. 
29.            return base.BindModel(controllerContext, bindingContext);
30.        }

No answers yet. Maybe you can help?

Tags
Grid
Asked by
ankit
Top achievements
Rank 1
Share this question
or