我有一个MVC Web API端点
[HttpPost]
public ReadQuoteForClientIdResponse ReadQuoteForClientId
(
ReadQuoteForClientIdRequest readQuoteForClientIdRequest
)
{
return new ReadQuoteForClientIdResponseMapper().Map
(
new ReadQuoteWorkflowHelper().ReadForClientId(readQuoteForClientIdRequest.ClientId)
);
}
端点将ReadQuoteForClientIdRequest
作为参数
public class ReadQuoteForClientIdRequest
{
public int ClientId { get; set; }
}
我试图做一个简单的帖子并且到达控制器,但由于某种原因,ClientId
始终为0。
function quoteGridController($scope, $http) {
$scope.quotes = [];
$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";
$http.post("http://localhost:57048/service/Quote/ReadQuoteForClientId", { "ClientId": "2" })
.success(function(data) {
})
.error(function(data) {
alert("Error occured " + data);
});
}
答案 0 :(得分:0)
好的,我将参数传递给$.Param
来解决问题
$http.post("http://localhost:57048/service/Quote/ReadQuoteForClientId", $.param({ "ClientId": 2 }))
.success(function(data) {
})
.error(function(data) {
alert("Error occured " + data);
});