web-api POST body object always null

前端 未结 26 3063
余生分开走
余生分开走 2020-11-27 15:03

I\'m still learning web API, so pardon me if my question sounds stupid.

I have this in my StudentController:

public HttpResponseMessage          


        
26条回答
  •  广开言路
    2020-11-27 15:21

    I spend several hours with this issue... :( Getters and setters are REQUIRED in POST parameters object declaration. I do not recommend using simple data objects (string,int, ...) as they require special request format.

    [HttpPost]
    public HttpResponseMessage PostProcedure(EdiconLogFilter filter){
    ...
    }
    

    Does not work when:

    public class EdiconLogFilter
    {
        public string fClientName;
        public string fUserName;
        public string fMinutes;
        public string fLogDate;
    }
    

    Works fine when:

    public class EdiconLogFilter
    {
        public string fClientName { get; set; }
        public string fUserName { get; set; }
        public string fMinutes { get; set; }
        public string fLogDate { get; set; }
    }
    

提交回复
热议问题