Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 从dropdownList获取的值仅更改一次?_Jquery_Ajax - Fatal编程技术网

Jquery 从dropdownList获取的值仅更改一次?

Jquery 从dropdownList获取的值仅更改一次?,jquery,ajax,Jquery,Ajax,我有jqueryajax函数来获取作为控制器参数的值,并将HTML发送回maycart表 $(document).ready(function () { $(".Quantity").change(function () { var ProID = $(this).attr("data"); var Quatity = $(".Quantity").val(); $.ajax({ type: "GET", u

我有jqueryajax函数来获取作为控制器参数的值,并将HTML发送回maycart表

    $(document).ready(function () {
    $(".Quantity").change(function () {
        var ProID = $(this).attr("data");
        var Quatity = $(".Quantity").val();
        $.ajax({
            type: "GET", url: "/Cart/UpdateValue", data: { ProID: ProID, quantity: Quatity },
            success: function (data) {
                $(".cart_box").html(data);

            }
        }
            );
    });
});
所以在我看来

<tbody>
                @foreach (var line in Model.Cart.Lines)
                {
                    <tr>

                        <td>@line.Product.Name
                        </td>
                        <td style="text-align: center; padding: 0">@Html.DropDownList("Quantity", new SelectList(ViewBag.Items as System.Collections.IList, "Value", "Text", line.Quantity.ToString()), new { data=line.Product.ProductID ,@class="Quantity"})</td>
                        <td>@string.Format("{0:00,0 VNĐ}", line.Product.Price)</td>
                        <td>@string.Format("{0:00,0 VNĐ}", (line.Quantity * line.Product.Price))</td>
                        <td>Button</td>
                    </tr>
                }

            </tbody>`

@foreach(Model.Cart.line中的var行)
{
@line.Product.Name
@Html.DropDownList(“数量”,新选择列表(ViewBag.Items as System.Collections.IList,“Value”,“Text”,line.Quantity.ToString()),新{data=line.Product.ProductID,@class=“Quantity”})
@string.Format(“{0:00,0 VNĐ}”,line.Product.Price)
@格式(“{0:00,0 VNĐ}”,(line.Quantity*line.Product.Price))
按钮
}
`
如果我更改dropdownlist中的值,则只会在第一行中发生一次。有人能告诉我我的错误是什么吗? 编辑:这是我的购物车索引视图控制器:

 public ViewResult Index(string returnUrl)
    {
        List<SelectListItem> items = new List<SelectListItem>();
        for (int i = 1; i <= 10; i++)
        {
            items.Add(new SelectListItem { Text = i.ToString(), Value = i.ToString() });
        }
        ViewBag.Items = items;
        return View(new CartIndexViewModel { Cart = GetCart(), ReturnUrl = returnUrl });
    }
公共视图结果索引(字符串返回URL) { 列表项=新列表();
对于(inti=1;i,似乎您正在成功内部用新列表替换旧列表-

在这种情况下,您可以尝试像这样使用事件委派-

$(document.body).on('change','.Quantity',function () {

是只调用一次事件处理程序还是只发送一次ajax请求?将选项
cache:false
设置为ajax options@Arun P Johny:ajax请求在我第一次更改dropdownlist的值时只发送一次。因此第二次不会更改。请尝试cache:false,不工作。当我有多行时,当我更改了一个dropdownlist的值,它在另一个dropdownlist.Sr中更改了所有相同的值,因为我的英语不好。是的,当我更改第二行的dropdownlist值时,它也更改了第一行的相同值。
$(document.body).on('change','.Quantity',function () {