【发布时间】: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>
【问题讨论】:
-
你确定不是加了
string值1而不是整数1? -
正如你在我的调试值中看到的那样,键是 41769,它的值是 1,而不是“1”。
-
将其更改为
dict[key] = parseInt(qty, 10);以确保 -
我按照您的建议修改了代码,在调试过程中,得到了完全相同的值,但消息仍然出现......我只是没有得到这个让我非常头疼的简单错误:(
标签: c# javascript jquery dictionary devexpress