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

DateTime Binding in AspNet Core

4 Answers 411 Views
Spreadsheet
This is a migrated thread and some comments may be shown as answers.
Nareg
Top achievements
Rank 1
Nareg asked on 19 Sep 2018, 10:27 PM

Hi 

I have problem binding DateTime field. I modified your example :https://demos.telerik.com/aspnet-mvc/spreadsheet/datasource

and added 

 [DataType(DataType.Date)]
        public DateTime TimeTest 
        {
            get;
            set;
        } = DateTime.Today;

to SpreadsheetProductViewModel.cs 

It displays the TimeTest field properly in excel sheet, but if I modify the date and submit the change, ModelState validation fails with following error:

The models contain invalid property values.The value 'Sat Jan 20 2018 00:09:00 GMT-0800 (Pacific Standard Time)' is not valid for TimeTest.

 

Please advice,

Thank you,

 

 

 

 

 

 

 

4 Answers, 1 is accepted

Sort by
0
Accepted
Joana
Telerik team
answered on 21 Sep 2018, 11:22 AM
Hi Nareg,

The issue stems from the way data is sent to the server. So, the changes in the demo that should be made in order to work for dates are as follows:

function onSubmit(e) {
    $.ajax({
        type: "POST",
        url: '@Url.Action("Data_Source_Products_Submit", "Spreadsheet")',
        data: JSON.stringify(e.data),
        contentType: 'application/json; charset=utf-8',
        dataType: "json",
        success: function (result) {
            e.success(result.Updated, "update");
            e.success(result.Created, "create");
            e.success(result.Destroyed, "destroy");
        },
        error: function (xhr, httpStatusMessage, customErrorMessage) {
            alert(customErrorMessage);
        }
    });
}

public ActionResult Data_Source_Products_Submit([FromBody]SpreadsheetSubmitViewModel model)
{

 I hope this will fit to your scenario.

Regards,
Joana
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Nareg
Top achievements
Rank 1
answered on 21 Sep 2018, 02:27 PM

No it didn't solve the issue. After this change SpreadsheetSubmitViewModel properties {Created, Destroyed, Updated} are getting set to null, regardless of rows added or updated. So making this change causes all bindings to fail.

 

0
Nareg
Top achievements
Rank 1
answered on 21 Sep 2018, 03:02 PM

sorry, it works, I forgot to add:

contentType: 'application/json; charset=utf-8',

Thank you,
Nareg

0
Joana
Telerik team
answered on 24 Sep 2018, 02:20 PM
Hello Nareg,

Thank you for sharing the output from your test.

I am glad that everything works as expected now. Let me know if you have further questions.

Regards,
Joana
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Spreadsheet
Asked by
Nareg
Top achievements
Rank 1
Answers by
Joana
Telerik team
Nareg
Top achievements
Rank 1
Share this question
or