JavaScript:如何添加数量并在签出中查看

JavaScript:如何添加数量并在签出中查看,javascript,jquery,html,asp.net-mvc-4,Javascript,Jquery,Html,Asp.net Mvc 4,我有一个情况想问你们所有人下面这些图片。当我在其中键入数量并单击添加按钮时,Categories显示产品。它将链接到签出。我需要我刚才键入的数量,它将显示在结帐中。我想知道怎么做 @using (Html.BeginForm("AddToCart", "ShoppingCart", new { id=@bike.ProductID},FormMethod.Post)) { <input

我有一个情况想问你们所有人下面这些图片。当我在其中键入数量并单击添加按钮时,
Categories
显示产品。它将链接到
签出
。我需要我刚才键入的数量,它将显示在
结帐
中。我想知道怎么做

@using (Html.BeginForm("AddToCart", "ShoppingCart", new { id=@bike.ProductID},FormMethod.Post))
                        {
                            <input type="text" style="width: 30px;" maxlength="3" class="quantity" name="quantity" value="1" />
                            <input type="submit" value="Add to Cart" />
                        }

我刚刚更新了你的代码

由于应该发布附加值,我将使用带有提交按钮的表单,而不是ActionLink。过帐表单时,数量将发送到控制器的AddToCart操作

@using (Html.BeginForm("AddToCart", "ShoppingCart", new { id = @bike.ProductID }, FormMethod.Post))
{
  Qty:<input type="text" style="width: 30px;" maxlength="3" class="quantity" name="quantity" value="1" />
  <input type="submit" value="Add to cart" />
}

我想知道你想做什么?提供代码您哪里有问题我想做的是当我键入2个数量的产品,然后单击
Add
按钮,它链接到
Checkout
,其中包含我刚才键入的2个数量<代码>数量:@Html.ActionLink(“Add”,“AddToCart”,“ShoppingCart”,new{id=@bike.ProductID},”)
Html
JavaScript
更新你的问题,我已经更新了
Html
Action
@帕夫洛你好,布鲁诺五世!我从你的代码中修复了它,但它仍然不起作用。你能告诉我哪里错了吗?我认为它遗漏了一些JavaScript。Hello@Trung Pham,使用此表单时不需要JavaScript。从您更新的示例中,我看到您没有对数量做任何处理。我的猜测是将数量添加到购物车中。你能至少确认数量包含正确的值吗?你说的“不处理数量”是什么意思@Bruno V?你能解释得更具体一点吗?你是说我错过了这个:
数量:
@using (Html.BeginForm("AddToCart", "ShoppingCart", new { id = @bike.ProductID }, FormMethod.Post))
{
  Qty:<input type="text" style="width: 30px;" maxlength="3" class="quantity" name="quantity" value="1" />
  <input type="submit" value="Add to cart" />
}
        [HttpPost]
        public ActionResult AddToCart(int id, FormCollection form)
        {
            // Does quantity return the correct value?
            var quantity = form["quantity"];

            var addedProduct = BikesDB.Products.Single(product => product.ProductID == id);
            var cart = ShoppingCart.GetCart(this.HttpContext);

            // The quantity should be stored in the cart as well
            addedProduct.Quantity = quantity;

            cart.AddToCart(addedProduct);
            return RedirectToAction("Index");
         }