为什么angularjs $http post的payload没有绑定到输入模型中?
当调用该操作时,模型为null,request.params和request.forms没有显示表单被发送的任何迹象。但是fiddler请求显示payload被以JSON形式发送。
AngularJS:
$http({
method: "POST",
url: "price/add",
data: {
Id: $scope.id,
StoreId: $scope.storeid,
Name: $scope.name,
Manufacturer: $scope.manufacturer,
Price: $scope.price
}
})
模型:
public class PriceModel
{
public int? Id { get; set; }
public int? StoreId { get; set; }
public string Barcode { get; set; }
public string Name { get; set; }
public string Manufacturer { get; set; }
public DateTime Created { get; set; }
public double? Price { get; set; }
}
控制器和操作方法说明。
public class PriceController : Controller
{
[HttpPost]
public int Add(PriceModel price)
{
Fiddler:
POST http://localhost:4989/price/add HTTP/1.1
Host: localhost:4989
Connection: keep-alive
Content-Length: 70
Accept: application/json, text/plain, */*
Origin: http://localhost:4989
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36
Content-Type: application/json;charset=UTF-8
Referer: http://localhost:4989/
Accept-Encoding: gzip,deflate,sdch
Accept-Language: nb,no;q=0.8,en-US;q=0.6,en;q=0.4
{"id":"","storeid":"","name":"asdf","manufacturer":"asdf","price":123}
PriceModel
中也有一个名为“Price”的属性而感到困惑。您可以尝试将操作参数的名称改为其他名称吗? - Andy T