400 Error on Add record Post. ODataV4Adaptor -> OData endpoint. Model validation failed.

Hi There!

dotnet 5.0 - Blazor WASM hosted.
AspNetCore.Odata 8.0.3

I have OData set up in accordance with Microsoft.AspNetCore.Odata spec, and can successfully post new records to this controller manually using Microsoft.Odata.Client (7.9.4) from my client app. So i know the odata endpoint / controller / actions are routing correctly and working. 

SfGrid successfully reads and updates existing records using the edit mode (dialog, with template form).

However when I try to write a new record i get the following error back from the server with no opportunity to debug or inspect the modelstate.

  1. {type: "https://tools.ietf.org/html/rfc7231#section-6.5.1",…}
    1. status: 400
    2. title: "One or more validation errors occurred."
    3. traceId: "00-090616ce7c52b144b7fc9ae3310c6bca-b5dcb1dc81b15040-00"
    4. type: "https://tools.ietf.org/html/rfc7231#section-6.5.1"


My controller is quite simple:

        public async Task<IActionResult> Post(T item)

        {

            if (!ModelState.IsValid)

            {

                return BadRequest(ModelState);

            }

            _dbSet.Add(item);

            await _dbContext.SaveChangesAsync();

            return new CreatedODataResult<T>(item);

        }

I was hoping somebody had a working example of creating records using odatav4adapter and aspnetcore.odata 8.0.3 that I could look at. There may well be something wrong with my controller but am unsur


1 Reply

VN Vignesh Natarajan Syncfusion Team November 8, 2021 07:52 AM UTC

Hi Tom,  
 
Thanks for contacting Syncfusion support.  
 
Query: “I was hoping somebody had a working example of creating records using odatav4adapter and aspnetcore.odata 8.0.3 that I could look at 
 
As per your request, we have prepared a working sample as per your requirement and we are not able to reproduce the reported issue at our end. Kindly refer the below sample for your reference 
 
 
Note: to bind datasource to Grid, kindly change connection string in DataContext.cs file in Client project based on NORTHWND.MDF file in App_Data folder.  
 
After referring the sample if you are still facing the reported issue, kindly get back to us with more details about the issue.   
 
Regards,
Vignesh Natarajan
 


Loader.
Up arrow icon