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

The value '/Date(-62135578800000)/' is not valid for

4 Answers 1010 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alexandre
Top achievements
Rank 1
Alexandre asked on 04 Apr 2014, 06:09 PM
Hi everyone,

I'm using a Grid to ajax edit a simple model in the inline mode and on the Controller the ModelState.IsValid is always false.
The error message is "The value '/Date(-62135578800000)/' is not valid for Expiration."

I have attach the relevant code of my test application and would appreciate any help.


Thanks,
Alexandre Lefebvre

4 Answers, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 08 Apr 2014, 03:30 PM
Hi Alex,

The reason for current behavior is that the Grid build-in schema doesn't support complex models and the nested "Date" fields are not parsed. In current case I would suggest to flatter your model by creating new ViewModel and contain only the "id" of the "OtherClass" inside it. 

Another option is to use for example the "RequestEnd" event of the DataSource to manually parse the nested date:
dataSource.Ajax()
    .Events(e => e.RequestEnd("onRequestEnd"))

function onRequestEnd(e) {
    for (var i = 0; i < e.response.Data.length; i++) {
        if(e.response.Data[i].Other && e.response.Data[i].Other.Expiration) {
            e.response.Data[i].Other.Expiration = kendo.parseDate(e.response.Data[i].Other.Expiration);
        }
    }
}

Kind Regards,
Vladimir Iliev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
1
Alexandre
Top achievements
Rank 1
answered on 08 Apr 2014, 03:41 PM
Hi Vladimir,

Unfortunately flatten is not an option in my case. I'll will give a try to the second options, in the mean time I was able to work around the problem with a custom model binder for the datetime type.

protected void Application_Start()
        {
            ModelBinders.Binders.Add(typeof(DateTime), new CustomDateBinder());
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.NameIdentifier;
        }

public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var value = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);

            if (value.AttemptedValue.StartsWith("/Date("))
            {
                try
                {
                    DateTime date = new DateTime(1970, 01, 01, 0, 0, 0, DateTimeKind.Utc).ToUniversalTime();
                    string attemptedValue = value.AttemptedValue.Replace("/Date(", "").Replace(")/", "");
                    double milliSecondsOffset = Convert.ToDouble(attemptedValue);
                    DateTime result = date.AddMilliseconds(milliSecondsOffset);                    
                    result = result.ToUniversalTime();
                    return result;
                }
                catch
                {
                }
            }
            return base.BindModel(controllerContext, bindingContext);
        }
0
Anthony
Top achievements
Rank 1
answered on 21 Dec 2015, 05:32 PM
This was immensely helpful. What would be even more helpful would be a note of some kind in the MVC grid documentation.
0
Marcel Härry
Top achievements
Rank 1
answered on 01 Nov 2016, 09:32 AM
Could not find my failing datetime value, but this helped. Thank you!
Tags
Grid
Asked by
Alexandre
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Alexandre
Top achievements
Rank 1
Anthony
Top achievements
Rank 1
Marcel Härry
Top achievements
Rank 1
Share this question
or