Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc angularjs将数据发布到mvc控制器_Asp.net Mvc_Angularjs_Post - Fatal编程技术网

Asp.net mvc angularjs将数据发布到mvc控制器

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 () { }); 我想把这

我有使用angularjs的简单代码

 $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数据吗