In WebAPI, [FromUri] and [FromBody]

May 17 2021 9:29 AM
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."
 
 
And when I give ID as the [FromUri] and Employee as the [FormBody]. It  Updated Successfully.Pls share Your Idea.
 
 
Thanks in Advance.

Answers (4)