Asp.net mvc angularjs将数据发布到mvc控制器
我有使用angularjs的简单代码Asp.net mvc angularjs将数据发布到mvc控制器,asp.net-mvc,angularjs,post,Asp.net Mvc,Angularjs,Post,我有使用angularjs的简单代码 $http.post(postToCreateURL, addingProducts, { transformRequest: angular.identity, headers: {'Content-Type': undefined} }) .success(function () { }) .error(function () { }); 我想把这
$http.post(postToCreateURL, addingProducts, {
transformRequest: angular.identity,
headers: {'Content-Type': undefined}
})
.success(function () {
})
.error(function () {
});
我想把这些数据绑定到这个Mvc控制器上
[HttpPost]
public JsonResult Create(ProductModel model)
{
NorthwindEntities db = new NorthwindEntities();
var products = db.Products.Select(s => new ProductModel
{
ProductName = s.ProductName,
SupplierID = s.SupplierID,
CategoryID = s.CategoryID,
QuantityPerUnit = s.QuantityPerUnit,
UnitPrice = s.UnitPrice,
UnitsInStock = s.UnitsInStock,
UnitsOnOrder = s.UnitsOnOrder,
ReorderLevel = s.ReorderLevel,
Discontinued = s.Discontinued
}).Take(5).ToList();
return Json(products, JsonRequestBehavior.AllowGet);
}
在这种情况下,我得到的是空值。提前谢谢 试试这个:
var request = {
ProductName: 'aa',
SupplierID: 'aa',
CategoryID: 'aa',
...
Discontinued: 'zzz'
}
$http.post(" URL IN HERE ", JSON.stringify(request), {
headers: {
'Content-Type': 'application/json'
}
})
标题:{'Content-Type':undefined}?如果我没有使用它,它在发送请求时会返回错误,如果您使用application/json,则无法发送。您能告诉我如何在mvc控制器中使用angularjs控制器发送的json数据吗