Web API complex parameter properties are all null

前端 未结 18 1533
长情又很酷
长情又很酷 2020-11-30 04:18

I have a Web API service call that updates a user\'s preferences. Unfortunately when I call this POST method from a jQuery ajax call, the request parameter object\'s proper

18条回答
  •  野性不改
    2020-11-30 05:20

      public class CompanyRequestFilterData
        {
                 public string companyName { get; set; }
                 public string addressPostTown { get; set; }
                 public string businessType { get; set; }
                 public string addressPostCode{ get; set; }
                 public bool companyNameEndWith{ get; set; }
                 public bool companyNameStartWith{ get; set; }
                 public string companyNumber{ get; set; }
                 public string companyStatus{ get; set; }
                 public string companyType{ get; set; }
                 public string countryOfOrigin{ get; set; }
                 public DateTime? endDate{ get; set; }
                 public DateTime? startDate { get; set; }
    }
    

    webapi controller

        [HttpGet("[action]"),HttpPost("[action]")]
        public async Task> GetCompanyRequestedData(CompanyRequestFilterData filter)
        {}
    

    jsvascript/typescript

    export async function GetCompanyRequesteddata(config, payload, callback, errorcallback) {
    await axios({
        method: 'post',
        url: hostV1 + 'companydata/GetCompanyRequestedData',
        data: JSON.stringify(payload),
        headers: {
            'secret-key': 'mysecretkey',
            'Content-Type': 'application/json'
        }
    })
        .then(res => {
            if (callback !== null) {
                callback(res)
            }
        }).catch(err => {
            if (errorcallback !== null) {
                errorcallback(err);
            }
        })
    

    }

    this is the working one c# core 3.1

    my case it was bool datatype while i have changed string to bool [companyNameEndWith] and [companyNameStartWith] it did work. so please check the datatypes.

提交回复
热议问题