Web API complex parameter properties are all null

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

    Maybe it will help, I was having the same problem.

    Everything was working well, and suddently, every properties was defaulted.

    After some quick test, I found that it was the [Serializable] that was causing the problem :

    public IHttpActionResult Post(MyComplexClass myTaskObject)
    {
        //MyTaskObject is not null, but every member are (the constructor get called).
    }
    

    and here was a snippet of my class :

    [Serializable]  <-- have to remove that [if it was added for any reason..]
    public class MyComplexClass()
    {
         public MyComplexClass ()
         {
            ..initiate my variables..
         }
    
         public string blabla {get;set;}
         public int intTest {get;set;
    }
    

提交回复
热议问题