Sti*_*ahl 5 asp.net-mvc asp.net-mvc-4 angularjs
为什么来自angularjs $ http帖子的有效负载没有绑定到输入模型?
调用该操作时,模型为null,request.params和request.forms不显示发送表单的任何迹象.但是小提琴请求表明有效载荷是用JSON发送的.
AngularJS:
$http({
method: "POST",
url: "price/add",
data: {
Id: $scope.id,
StoreId: $scope.storeid,
Name: $scope.name,
Manufacturer: $scope.manufacturer,
Price: $scope.price
}
})
Run Code Online (Sandbox Code Playgroud)
模型:
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; }
}
Run Code Online (Sandbox Code Playgroud)
控制器和动作方法描述
public class PriceController : Controller
{
[HttpPost]
public int Add(PriceModel price)
{
Run Code Online (Sandbox Code Playgroud)
小提琴手:
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}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8283 次 |
| 最近记录: |