I am a beginner in mvc and am developing an ecommerce website.
In my cart list i need to enter specific quantity to calculate the total price with out page refresh. 
I used a java script call inside the foreach statement and it worked, like when i enter quantity and clicked the "**TotalPrice**" field the price will automatically calculated and displays.

But now i need to update my db with the new entered quantity and total price when i clicked into the "**TotalPrice**" field 

I am trying ajax but am not familiar with it

My view

```
                <table class="table">

                        @{
                            int i = 0;

                            foreach (var item in lscart)
                            {
                                i = i + 1;
                                <tr>
                                    <td>@Html.HiddenFor(modelItem => item.CProductID, new { htmlAttributes = new { @class = "form-control", @id = "pid" + @i } })</td>
                                    <td>
                                        @{
                                var base64 = Convert.ToBase64String(item.CImage);
                                var imgSrc = String.Format("data:image/jpg;base64,{0}", base64);
                                <img src='@imgSrc' style="width:100px; height:100px;" />
                                        }
                                    </td>
                                    <td>@Html.DisplayFor(modelItem => item.CProductName)</td>
                                    <td>Rs.</td>
                                    <td>@Html.EditorFor(modelItem => item.CPrice, new { htmlAttributes = new { @class = "form-control", @readonly = "readonly", @id = "cprice" + @i } })</td>

                                    <td>
                                        <div class="col-md-6">

                                            @Html.EditorFor(modelItem => item.Cquantity, new { htmlAttributes = new { @class = "form-control", @placeholder = " Qty", @id = "qt" + @i } })

                                        </div>

                                    </td>

                                    <td>
                                        <div>
                                            @Html.EditorFor(modelItem => item.CTotalPrice, new { htmlAttributes = new { @class = "form-control", @readonly = "readonly", @placeholder = " Total Price", @id = "total" + @i, @onclick = "edValueKeyPress(" + @i + ")", @onkeyup = "edValueKeyPress(" + @i + ")" } })

                                        </div>
                                    </td>

                                    <td><a href="#"><i class="fa fa-close"></i></a></td>
                                </tr>
                            }
                        }

                    </table>

```

My javascript for total price calculation without page refresh

```
<script>
    function edValueKeyPress(i) {

        //alert(i);
        var edValue = document.getElementById("qt" + i);
        var edValue1 = document.getElementById("cprice" + i);
        var s = edValue.value * edValue1.value;
        var t = document.getElementById("total" + i);
        t.value = s;

    }
</script>

```

My ajax code (this is not completed and i dont know where to call this ajax function in my view)

```
<script type="text/javascript">

    $(document).ready(function () {
        alert('ready');
        var quantity = document.getElementById("qt" + i);
        var proid = document.getElementById("pid" + i);
        var price = document.getElementById("cprice" + i);
            $.ajax({
                url: '/Products/Cartup',
                type: "GET",
                data: { quantity: quantity, proid: proid, price: price },
                dataType: "JSON",
                success: function (rslt) {

                },
                error: function (rslt) {

                }
            });

    })
    </script>

```

My Controler actionmethod

```
 public ActionResult Cartup(int quantity, int proid,float price)
    {
        var Cert = (from cert in db.TBL_Cart where cert.CProductID == proid select cert).FirstOrDefault();
        if (Cert != null)
        {
            int priceint= Convert.ToInt32(price);
            Cert.Cquantity = quantity;
            Cert.CTotalPrice = quantity * priceint;
            db.Entry(Cert).State = EntityState.Modified;
            db.SaveChanges();
        }

        return View();
    }

```

My DB Table Design

<https://i.stack.imgur.com/mh9F7.png>

My full sourcecode with db

<https://www.dropbox.com/s/4iegq4kpsoqoue1/backup%20of%20indianhub.zip?dl=0>

Controller :ProductsController,
View:cartlist