Home Error 500 internal server error in asp.net
Reply: 0

Error 500 internal server error in asp.net

user1215
1#
user1215 Published in June 20, 2018, 1:29 am

I am writing an asp.net application and am trying to make a post request using jquery ajax to web api2 controller method. Doing so results in error 500 internal server error. Here is the jquery code

function reload(quantity, cartItemId) {
        $.ajax({
            url: "/api/user/UpdateCart",
            method: "POST",

            data: { quantity: quantity, cartItemId:cartItemId },
            success: function() {
              //  window.location.href = "/user/ViewCart";
            }

    });
    }

    function addItem(cartItemId) {
        var quantity = parseInt(document.getElementById("txt-box-" + cartItemId).value);
        quantity++;
        document.getElementById("txt-box-" + cartItemId).value = quantity;
        reload(quantity,cartItemId);
    }

In my web api 2 controller I have the following code

    [AllowAnonymous]
    [HttpPost]
    public IHttpActionResult UpdateCart([FromBody]int quantity,[FromBody]int cartItemId)
    {
        var cartItemInDb = _unitOfWork.CartItemRepository.Read(cartItemId);
        cartItemInDb.Quantity = quantity;
        _unitOfWork.Complete();

        return Ok();
    }
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.319097 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO