Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have simple code using angularjs,

 $http.post(postToCreateURL, addingProducts, {
        transformRequest: angular.identity,
        headers: {'Content-Type': undefined}
    })
        .success(function () {
        })
        .error(function () {
        });

And I want bind this data to this Mvc controller

[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);
    }

In this situation I'm getting null values. Thanks in advance!

share|improve this question
    
headers: {'Content-Type': undefined} ? –  Ben Diamant Dec 17 '14 at 13:40
    
if I did't use this it has returned error while sending request and couldn't send –  Hayot Ismatov Dec 17 '14 at 13:52
    
If you use application/json? –  Ben Diamant Dec 17 '14 at 13:57

1 Answer 1

Try this:

     var request = {
        ProductName: 'aa',
        SupplierID: 'aa',
        CategoryID: 'aa',

        ...

        Discontinued: 'zzz'
    } 




    $http.post(" URL IN HERE ", JSON.stringify(request), {
        headers: {
            'Content-Type': 'application/json'
        }
    })
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.