Search code examples
c#asp.net-web-apifiddler

webapi httppost sending the parameter as object


I have a webapi method as httppost as shown below. I am trying to make a request using fiddler but I cant get param object. It is null if I send the request as shown in the image. what am I doing wrong?

  [ActionName("getCustomerByName")]
    [HttpPost]
    public async Task<List<Customer>> GetcustomerByName(object param)
    {

    }

enter image description here


Solution

  • What do you expect object param to be?

    Does the request body JSON string represent a Customer ?

    If yes, use Customer as the type instead of object eg

    public async Task<List<Customer>> GetCustomerByName(Customer param)
    

    If no then define a class (Any name) with the same field names as the JSON string you are passing and use that class instead of object eg

    public class QueryArgs
    {
       public int Id { get; set; }
       // rest of your fields go here
    }
    
    public async Task<List<Customer>> GetCustomerByName(QueryArgs param)