How to post an object to WebAPI

前端 未结 1 1491
醉话见心
醉话见心 2020-12-21 19:32

I\'m trying to figure out how to post an object from my form to a web api service. Within my controller I defined a model that I wanted to add input values to.



        
相关标签:
1条回答
  • 2020-12-21 20:10

    It seems like you may be doing an extra step. You don't need to encode in json then pass in in json

    return $http.post('reportLibrary/createlabel/', { LabelId: 101, LabelName: 'myname' }, {
    

    then

     public DTOs.ReportLabel CreateLabel([FromBody]ReportLabel reportLabel)
    

    Take a look at the network values going by and you should see in debug tools or fiddler the actual posted values (form values).

    0 讨论(0)
提交回复
热议问题