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.
vijayaasri palaniappanPosted May 17, 2021, 12:01 PM
try
{
Sachin SinghPosted May 17, 2021, 11:04 AM
vijayaasri palaniappanPosted May 17, 2021, 10:54 AM
Sachin SinghPosted May 17, 2021, 9:49 AM
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.