【问题标题】:Type error with dictionary object字典对象的类型错误
【发布时间】:2013-09-06 14:58:06
【问题描述】:

更改数量值后尝试单击表单上的按钮时出现以下错误。正确设置了键和数量(正如我在调试过程中看到的那样)。

我不知道为什么会出现错误......

The value "1" is not of type "System.Int32" and cannot be used in this generic collection.
Parameter name: value

我在网上查到了这条消息,但我读到的内容都无法解释问题所在。

我的字典对象设置如下。请注意,我尝试将类型更改为字符串、字符串,然后出现(上图)相同的消息,但不是 "System.Int32""System.String"

PageData["ClientSelectedQtyRows"] = new Dictionary<string, Int32>();

这是我在屏幕上更改数量值时触发的 JS:

function UpdateQtySelection(key, qty) {
            if (key) {
                var dict = PageDataClient.Get("ClientSelectedQtyRows");
                dict[key] = qty;
                PageDataClient.Set("ClientSelectedQtyRows", dict);
            }
        }

在调试过程中,字典对象在我更改数量后包含正确的值。

?dict[key]
1

?PageDataClient.Get("ClientSelectedQtyRows")
{...}
    [prototype]: {...}
    [41769]: 1
    [prototype]: [] 

打印按钮的标记如下:

<td style="padding-right: 10px;">
                                    <dx:ASPxButton ID="btnPrint" Text="Print" runat="server" ClientInstanceName="btnPrintClient" CausesValidation="false" ValidationGroup="CS" Theme="PlasticBlue" AutoPostBack="false" Enabled="false">
                                        <ClientSideEvents Click="function (s,e) { PerformCallback('1:'); btnPrintClient.disabled = true; btnSearchClient.disabled = true; }" />
                                    </dx:ASPxButton>
                                </td>

【问题讨论】:

  • 你确定不是加了string1而不是整数1?
  • 正如你在我的调试值中看到的那样,键是 41769,它的值是 1,而不是“1”。
  • 将其更改为 dict[key] = parseInt(qty, 10); 以确保
  • 我按照您的建议修改了代码,在调试过程中,得到了完全相同的值,但消息仍然出现......我只是没有得到这个让我非常头疼的简单错误:(

标签: c# javascript jquery dictionary devexpress


【解决方案1】:

由于 ASPXHiddenField 不支持字典对象中的整数,因此我将其制成 .

在 JS 功能期间,我错过了一件事情要做。

我将值更改为:

dict[key] = parseInt(qty, 10);

dict[key] = qty.toString();

这样就解决了问题...

【讨论】:

    猜你喜欢
    • 2013-03-02
    • 1970-01-01
    • 2018-02-27
    • 2021-08-29
    • 1970-01-01
    • 1970-01-01
    • 2011-10-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多