POSTing from Angular to .net WebAPI

前端 未结 2 1721
你的背包
你的背包 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:57

    You could use the $http module.

    Here's an example:

    
    
    
    
        
        Index
    
    
        
    • FirstName: {{person.FirstName}}
    • LastName: {{person.LastName}}
    • UserName: {{person.Username}}
    • IsApproved: {{person.IsApproved}}
    • IsOnlineNow: {{person.IsOnlineNow}}
    • IsChecked: {{person.IsChecked}}

    Assuming the following controller:

    public class ValuesController : ApiController
    {
        [HttpPost]
        public User Post(User model)
        {
            return model;
        }
    }
    

提交回复
热议问题