Question Background:

I am trying to pass two parameters (product name and price) from a View to an 'AddToCart' method on my MVC Controller. I'm doing this by passing the parameters to a JQuery Ajax function.


Currently when clicking the 'Add To Cart' button 'link' the script is not being triggered. There is no error but the process is not taking place.

Here is the code:

<script src=""></script>

<h3 class="panel-title boldFeatures" id="name">@(( as List<LoginTest.Models.HomePageItem>).First().ProductName)</h3>

<p id="price">@(( as List<LoginTest.Models.HomePageItem>).First().productPrice)</p>

<a class="btn btn-primary btn-block" id="addToCart">Test</a>

    $("#addToCart").on('click',function (e) {
            url: '/HomePage/AddToCart',
            data: { name: $('#name').text(), qty: $('#price').text() },


//Method on controller:
 public void AddToCart(string name, string qty)
       //Logic for adding to the cart.

Related posts

Recent Viewed