POSTing from Angular to .net WebAPI

前端 未结 2 1723
你的背包
你的背包 2020-12-05 14:04

I\'m using an Angular $resource to post a model to a webapi endpoint, but Angular sends the data in the request payload, rather than a JSON body or form parameters. As a res

2条回答
  •  春和景丽
    2020-12-05 14:35

    For me this just worked fine. Below is the server-side code

        [HttpPost]
        public void Disconnect([FromBody] Models.Users.User model) { ... }
    

    and the requesting client code will be,

    var dataToPost ={ id : 3, firstName : 'Test', lastName : 'User', username : 'testuser', isApproved : true, isOnlineNow : true, isChecked: true };
    
                var config = {
                    headers : {
                        'Content-Type': 'application/json;charset=utf-8;'
                    }
                }
                $http.post(thisIsUrl, dataToPost, config).then(......
    

提交回复
热议问题