Salut tout le monde,
je suis en cours de réalisation d'un panier asp.net mvc c#
J'essaie d'envoyer une valeur "quantité" d'un textbox qui n'appartient à mon modèle "produit" au controller
j'ai essayé avec ajax mais rien ne se passe . au faite mon script ne s'exécute pas et mon panier se rempli avec le produit sans la quantité qui reste nulle.
voila mon view
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 <script> $('.Sendparams').click(function (e) { e.preventDefault(); debugger; var produitId = $(this).val(); var quant = $("#quant").val(); $.ajax({ type: 'GET', url: '/ShoppingCart/AddToCart', data:{ "Id": produitId , "quant": quant }, success: function (response) { $("#mainContainerCenter").html(response); } });}); </script> @model testingtemplate.Models.Categorie @{ ViewBag.Title = "Browse Produits"; Layout = "~/Views/Shared/_Layout2.cshtml"; } <div class="content-wrapper"> <!-- Content Header (Page header) --> <section class="content-header"> <h3>@Model.Nom_categorie </h3> </section> <!-- Main content --> <section class="content"> <!-- Small boxes (Stat box) --> <div class="row"> <ul> @foreach (var album in Model.Produits) { <div class="col-lg-3 col-xs-6"> <li>@album.Nom_Produit</li> <li>@album.Categorie.Nom_categorie</li> <li>@String.Format("{0:F}", album.Prix)</li> <li>@Html.TextBox("quant")</li> <li>@Html.Hidden("produitId", album)</li> <li> <p class="button"> @Html.ActionLink("voila","AddToCart","ShoppingCart", new { id = album.ProduitId }, new { @class = "Sendparams"}) </p> </li> </div> } </ul> </div> </section> </div>
ainsi que mon controller
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 public ActionResult AddToCart(int id , string quant) { // Retrieve the album from the database var addedAlbum = storeDB.Produits .Single(album => album.ProduitId == id); // Add it to the shopping cart var cart = ShoppingCart.GetCart(this.HttpContext); cart.AddToCart(addedAlbum,quant); // Go back to the main store page for more shopping return RedirectToAction("Index"); }
Je sais que je looupe quelque chose mais je ne sais pas quoi vraiment
Partager