【发布时间】:2014-08-08 06:33:16
【问题描述】:
我真的不知道如何使用 web api 的 PUT 方法从角度传递参数。
我了解 GET 方法是如何执行的,但 PUT、POST 和 DELETE 对我来说真的很难。
我看了很多文章,但还是不明白
我的 web api 的控制器中有这样的代码:
static readonly IProfile profileRepository = new ProfileRepository();
[Route("api/profile/")]
[HttpGet]
[System.Web.Http.AcceptVerbs("GET")]
public IEnumerable<Profile> getProfiles()
{
return profileRepository.getProfiles();
}
[Route("api/profile/")]
[HttpPut]
[System.Web.Http.AcceptVerbs("PUT")]
public IEnumerable<Profile> putProfile(Profile profile)
{
profileRepository.putProfile(profile);
return getProfiles();
}
我的 angularJS 中也有这样的服务
var _putProfile = function (name,address,contacts) {
return $http.put(serviceURL + 'api/profile/Name=' + name + '&Address=' + address + '&Contact=' + contacts).then(function (results) {
return results;
});
};
当我使用Postman 应用程序时,当我使用x-www-form-urlencoded 时,web api 执行良好,它将数据从邮递员传递到 web api,但如何将数据从 angularJS 传递到 web api。
有没有人可以在这里给我一个最佳答案..请给我一个想法如何做到这一点,并请告诉我什么是最佳做法..
我只是 angularJS 和 Web Api 的新手,请指导我.. 非常感谢
【问题讨论】:
标签: asp.net angularjs asp.net-web-api asp.net-web-api2