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

DateTime problem with odata and datasource

1 Answer 251 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Walter
Top achievements
Rank 1
Walter asked on 17 Jul 2012, 02:45 PM
Hello to everyone, I'm getting trouble with odata and datasource. I've an entity wich has a lot of date time fields wich are exposed by a grid. When I try to make an update i got this error: 
400 Bad Request
 
The field xxxx cannot be converted to DateTime etc etc...... string is not a valid date time value.  
Looking to POST request I've seen that the key /value pairs have this format: 
"Expiry_Date":"/Date(-6847804800000)/" 
I got this exception:
 "type": "System.FormatException", "stacktrace": " in System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles)\r\n in System.Convert.ToDateTime(String value, IFormatProvider provider)\r\n in System.String.System.IConvertible.ToDateTime(IFormatProvider provider)\r\n in System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)\r\n in System.Data.Services.Serializers.JsonDeserializer.ConvertValues(Object value, String propertyName, Type typeToBeConverted, DataServiceProviderWrapper provider)" 

Below there is the datasource and grid definitions:

var dataSource = new kendo.data.DataSource({
    type: "odata",
    serverPaging: true,
    serverSorting: true,
    serverFiltering: true,
    pageSize: 20,
    batch: false,
    schema: {
        model: {
            id: "No_",
            fields: {
                No_: { type: "string" },
                Customer_WR_Code: { type: "string" },
                Description: { type: "string" },
                State: { type: "string" },
                Creation_Date: { type: "date" },
                Creation_Time: { type: "date" },
                Closing_Date: { type: "date" },
                Closing_Time: { type: "date" },
                Cancelling_Date: { type: "date" },
                Cancelling_Time: { type: "date" },
                Expiry_Date: { type: "date" },
                Appointment_Begin_Date: { type: "date" },
                Appointment_Begin_Time: { type: "date" },
                Appointment_End_Time: { type: "date" },
                Appointment_End_Date: { type: "date" },
                DateTime_Field_1: { type: "date" },
                DateTime_Field_2: { type: "date" },
                Date_Field_1: {type:"date"},
                Date_Field_2: {type:"date"}
 
            }
        }
    },
    transport: {
        read: "WCFDB.svc/View_Work_Request",
        update: {
            url: "WCFDB.svc/View_Work_Request",
            type: "POST",
            dataType: "json"
        }       
    }
 
});


$("#grid").kendoGrid({
             dataSource: dataSource,
             height: 550,
             pageable: {
                 refresh: true,
                 pageSizes: true
             },
             reorderable: true,
             editable: "inline",
             sortable: true,
             filterable: true,
             columnMenu: true,              
             navigatable: false,
             resizable: true,
             toolbar: kendo.template($("#tmplToolBar").html()),
             change: function (e) {
                 var grid = $("#grid").data("kendoGrid");
                 var model = grid.dataItem(grid.select());
                 refreshTab(model);
             },
             dataBound: function (e) { var item = e.sender.dataSource.at(0); refreshTab(item); },
             selectable: "row",
             columns: kendoGridColumns               
         });

Here the service:


[JSONPSupportBehavior]
 public class WCFDB : DataService<WOMContainer>
 {
     // Questo metodo viene chiamato solo una volta per inizializzare i criteri a livello di servizio.
     public static void InitializeService(DataServiceConfiguration config)
     {
         // TODO: impostare regole per indicare i set di entità e le operazioni del servizio visibili, aggiornabili e così via.
         // Esempi:
         config.SetEntitySetPageSize("*", 20);       
         config.SetEntitySetAccessRule("*", EntitySetRights.All);
         config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
         config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
         config.UseVerboseErrors = true;   
     }
     ................................
     ................................
     ................................
     ................................



1 Answer, 1 is accepted

Sort by
0
Seminda
Top achievements
Rank 1
answered on 20 Jul 2012, 10:24 AM
Following links solve your problem.
http://www.kendoui.com/documentation/ui-widgets/grid/configuration.aspx

http://www.kendoui.com/forums/framework/globalization/kendo-fails-to-parse-or-format-utc-dates.aspx


Tags
Data Source
Asked by
Walter
Top achievements
Rank 1
Answers by
Seminda
Top achievements
Rank 1
Share this question
or