I have a Balzor WASM App generated using Radzen, It works fine.
But what I normally do is take code from the generated code and integrate into my Project.
I'm finding the Controller [FromBody] returns null in my code but fine in the generated code. I've tried everything but I'm not finding any solution. Is there something I'm missing. I've checked that I've added the package Newtonsoft.Json.
item returns object in the generated code but the same code copied to the project returns null. If in my code I change Models.QpmsNet5.Supplier to dynamic, I am able to deserialize with both Newtonsoft.Json as well as System,Text.Json.
Models.QPMSNet5.Supplier result = Newtonsoft.Json.JsonConvert.DeserializeObject<Models.QPMSNet5.Supplier>(item.ToString());
Models.QPMSNet5.Supplier result2 = System.Text.Json.JsonSerializer.Deserialize<Models.QPMSNet5.Supplier>(item.ToString());
Any ideas on why the item is null from the Controller?.
I created another model and called it SupplierDto and copying everything from Supplier.cs except change the name. This time passing from Add Supplier, the Controller has the value in the item.
I thought it was issue with name. So I started again but this time instead of creating new SupplierDto.cs, I renamed Supplier.cs to SupplierDto.cs (noting that all references to Supplier are changed to SupplierDto). But now null in the item.
Did a bit of investigation (maybe more than just a bit)
The current route for the Controller is: [Route("odata/QPMSNet5/Suppliers")] and the item is null eventhough if I change the type to dynamic, there is data in FromBody.
I found after lot of trial and error that if I change the route, the item does have content eg. of changes [Route("odata/QPMSNet5/SuppliersNew")] or [Route("odata/QPMSNet5/internal/Suppliers")]. I don't know enough about OData to determine why it starts working if I change the route. The generated code works fine but transferring this into my project doesn't without changing the route. I know something is different in my project but I don't know where to begin looking and am puzzled why changing the route makes it work
Unfortunately we haven't seen this error before and don't know what could be causing it provided that the generated application works fine. There could be a model parsing error. Check the ModelState property of the controller with your debugger and inspect the Errors. Probably this will give a hint why the model is null.