【问题标题】:Not able to retrieve hidden field value [closed]无法检索隐藏字段值[关闭]
【发布时间】:2018-11-03 10:24:02
【问题描述】:

我已将列表存储在隐藏字段中。

<input id="ProductList" name="ProductList" type="hidden" value="[{&quot;ProductDetailsID&quot;:303,&quot;Size&quot;:&quot;S&quot;,&quot;Color&quot;:&quot;White&quot;,&quot;SizeID&quot;:9,&quot;ColorID&quot;:11,&quot;MRP&quot;:2,&quot;SellingPrice&quot;:5,&quot;StockQuantity&quot;:5,&quot;ImageCount&quot;:1,&quot;IsDiscountPercent&quot;:&quot;%&quot;,&quot;ProductDiscount&quot;:0,&quot;ProductList&quot;:null}]">

我正在尝试使用 JQuery 检索值

$('#ProductList').val()

但我得到的是列表类型而不是实际的列表值

System.Collections.Generic.List`1[WebYedaz.Models.Data.Product.ProductDetails]

当我检查 DOM 但仍无法检索到它时,隐藏字段具有正确的值。我做错了什么?

【问题讨论】:

    标签: javascript c# jquery


    【解决方案1】:

    您的 ID 与您用于获取价值的书面 ID 不同。

    请更新如下:

    $("#ProductList").val();

    【讨论】:

    • 将其视为类型错误并在评论部分发布正确的值不是更正确吗?
    • 先生下次我会注意的
    • 即使使用 $("#ProductList").val() 我也无法得到结果。
    【解决方案2】:

    $(document).ready(function() {
    var value = $('#ProductList').val();
    console.log(value);
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <input id="ProductList" name="ProductList" type="hidden" value="[{&quot;ProductDetailsID&quot;:303,&quot;Size&quot;:&quot;S&quot;,&quot;Color&quot;:&quot;White&quot;,&quot;SizeID&quot;:9,&quot;ColorID&quot;:11,&quot;MRP&quot;:2,&quot;SellingPrice&quot;:5,&quot;StockQuantity&quot;:5,&quot;ImageCount&quot;:1,&quot;IsDiscountPercent&quot;:&quot;%&quot;,&quot;ProductDiscount&quot;:0,&quot;ProductList&quot;:null}]">

    【讨论】:

      【解决方案3】:

      您在 Jquery 代码中传递了错误的 id。我认为你应该尝试使用$('#ProductList').val() 而不是 $('#List').val()。

      【讨论】:

        猜你喜欢
        • 2012-05-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-02-06
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多