Hi,
In WebAPI, I pass the Id as the [FromBody]
{
"Id" : 1
} in JSOn Format.
and Employee as the [FormUri] for the PUT method. It Shows the error:
"Message": "The request is invalid.",
"MessageDetail": "The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Net.Http.HttpResponseMessage Put(Int32, EmployeeDataAccess.Employee)' in 'WebAPI.Controllers.EmployeesController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter."
"MessageDetail": "The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Net.Http.HttpResponseMessage Put(Int32, EmployeeDataAccess.Employee)' in 'WebAPI.Controllers.EmployeesController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter."
And when I give ID as the [FromUri] and Employee as the [FormBody]. It Updated Successfully.Pls share Your Idea.
Thanks in Advance.

Sachin SinghRank #66 · 26.2K reputationPosted May 17, 2021, 5:49 AM EDT
1. If a parameter is a primitive type like int, bool, double, etc, web API tries to get the value from the URI(either from the Routed data or query string).
2. If the parameter is a complex type like Employee, Customer, etc then web API tries to get the value from the request body.
vijayaasri palaniappan120 reputationPosted May 17, 2021, 6:54 AM EDT
Sachin SinghRank #66 · 26.2K reputationPosted May 17, 2021, 7:04 AM EDT
vijayaasri palaniappan120 reputationPosted May 17, 2021, 8:01 AM EDT
try
{