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

.net core spreadsheet trouble modeling my project after the Spreadsheet Datasource Binding demo

2 Answers 75 Views
Spreadsheet
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 11 Apr 2019, 08:01 PM

trying to implement this demo in our .net core project targeting core 2.1. taking one step at a time - 

I have modeled my view models based on your examples and my controller after your datasource controller - i don't use services

At this point I am able to bind and return data from our database. The spreadsheet is fine at this point and all I am trying to do now is get the data into the 

Controller submit method.

i have set up my ajax call as you have in the 2018 R2 release examples - for saving changes

    function onSubmit(e) {

         $.ajax({
             type: "POST",
             url: '@Url.Action("Data_Source_Products_Submit", "Spreadsheet")',
             data: e.data,
             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(xhr.responseText);
             }
         });
     }

When I hit Save and debug , I can see that the data is there in the updated array (the other 2 are empty)

however when i got to the controller - the ModelState was inValid

if I add the contentType: "application/json", then  ModelState will be valid but the input model updated parameter is null

 

just the fact that i need to add the content type to the ajax call tells me there is something fundamentally different between your core project and mine

your project has so many pieces I cannot easily if i am missing something simple or something big

 

Do you have any idea why i am needing to add the content type to get the ModelState valid?

And why the Updated array is null in the controller when I can see the data in the array on the client side?

 

thanks

Jim

2 Answers, 1 is accepted

Sort by
0
Veselin Tsvetanov
Telerik team
answered on 16 Apr 2019, 11:08 AM
Hi James,

You should not need to set the contentType of the request sent to properly communicate with the controller action. The ModelState.IsValid property would depend on the configuration of the ViewModel (the model of the items) and how its requirements are set. If at least one of them is violated, the model state will be invalid.

To better illustrate that scenario, I have prepared a small sample. You will find that project attached to my reply. Now, if run the sample and change some of the unit price values to a negative number, that will result in not valid ModelState. This restriction is configured in the SpreadsheetProductViewModel class:
[DataType(DataType.Currency)]
[Range(0, int.MaxValue)]
public decimal UnitPrice
{
    get;
    set;
}

Regards,
Veselin Tsvetanov
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
James
Top achievements
Rank 1
answered on 16 Apr 2019, 11:27 AM

Hi Veselin  - yes it is my view model - have quite a few data items in there - apparently not all defined correctly

thanks for your help

Tags
Spreadsheet
Asked by
James
Top achievements
Rank 1
Answers by
Veselin Tsvetanov
Telerik team
James
Top achievements
Rank 1
Share this question
or