这是WebApi控制器...在本代码中我得到一个null(产品)意味着当我发布数据时我得到产品为空。
// POST: api/Products
[ResponseType(typeof(Product))]
public IHttpActionResult PostProduct(Product product)
{
Product p = new Product();
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
p.ProductName = product.ProductName;
p.ProductDes = product.ProductDes;
p.AddCatagoryId = product.tblcatagory.Id;
p.AddSubCatagoryId = product.tblsubcatagory.Id;
p.Date = DateTime.Now.Date;
p.Inches = product.Inches;
p.ProductQty = product.ProductQty;
p.ProductRate = product.ProductRate;
db.products.Add(p);
db.SaveChanges();
return CreatedAtRoute("DefaultApi", new { id = product.Id }, product);
}
Angular Js Code ....我在(alert())中得到了正确的Pro值,但是当它转到这个POST:api / Products链接比我面对空值...你可以看到上面的代码。
$scope.submitProForm = function (isValid, Pro) {
if (isValid) {
alert(Pro.tblcatagory.Id); //here i get a corect value after load application
alert(Pro.ProductName); //here i get a corect value after load application
//cfpLoadingBar.start();
$http.post('/api/Products', Pro).then(function (response) {
//cfpLoadingBar.complete();
GetAllPro();
Notification.success('Data Added Successfully!');
},
function () {
Notification.error('Something Went Wrong!');
})
}
}