Web API complex parameter properties are all null

前端 未结 18 1502
长情又很酷
长情又很酷 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:25

    My issue was not solved by any of the other answers, so this solution is worth consideration:

    I had the following DTO and controller method:

    public class ProjectDetailedOverviewDto
    {
        public int PropertyPlanId { get; set; }
    
        public int ProjectId { get; set; }
    
        public string DetailedOverview { get; set; }
    }
    
    public JsonNetResult SaveDetailedOverview(ProjectDetailedOverviewDto detailedOverview) { ... }
    

    Because my DTO had a property with the same name as the parameter (detailedOverview), the deserialiser got confused and was trying to populate the parameter with the string rather than the entire complex object. The solution was to change the name of the controller method parameter to 'overview' so that the deserialiser knew I wasn't trying to access the property.

提交回复
热议问题