0

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!

4
  • headers: {'Content-Type': undefined} ? Commented Dec 17, 2014 at 13:40
  • if I did't use this it has returned error while sending request and couldn't send Commented Dec 17, 2014 at 13:52
  • If you use application/json? Commented Dec 17, 2014 at 13:57
  • can you please tell how you are consuming json data send by angularjs controller in your mvc controller Commented Jun 2, 2015 at 12:09

1 Answer 1

0

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'
        }
    })
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.