简体   繁体   English

在视图上,字符串未被识别为有效的布尔值复选框

[英]String was not recognized as a valid Boolean checkboxes on a view

I have went through many previous posts of this error. 我已经看过很多关于此错误的文章。 I have a dynamic list of items being displayed in a table and each row has a checkbox that I can check to delete that row or not on the post. 我有一个动态项目列表,这些项目显示在表中,并且每一行都有一个复选框,我可以选中该复选框以删除该行,也可以不删除该行。 Neither my boss or myself can figure out why we are getting this error on this line. 我的老板和我自己都无法弄清楚为什么我们在此行遇到此错误。 I have commented out all the code in the post action result so the same data is coming into the view each time. 我已经注释掉了post操作结果中的所有代码,因此每次相同的数据都会进入视图。

<td>@Html.CheckBox("LogsToDelete[" + i + "]", false, new { @value = log.ID, @class = "checkbox" })</td>

I am incrementing "i" during each loop to get a unique string name for each checkbox. 我在每个循环中递增“ i”以获得每个复选框的唯一字符串名称。 For some reason it doesn't like this. 由于某种原因,它不喜欢这样。 If I change "i" to a 4 or a 5 or(what ever number) the page reloads fine. 如果我将“ i”更改为4或5或(无论多少),页面将重新加载正常。 But with the "i" it throws this error. 但是使用“ i”会引发此错误。 I even tried building that portion before this line and then just sticking my temp variable in it but I still get the same error string-> bool error. 我什至尝试在此行之前构建该部分,然后将temp变量保留在其中,但仍然出现相同的错误字符串-> bool错误。

string temp = "LogsToDelete[" + i.ToString() + "]";

@Html.CheckBoxFor(m => m.LogsToDelete[i].Checked, new { @class = "checkbox" }) @Html.HiddenFor(m => m.LogsToDelete[i].LogID) @ Html.CheckBoxFor(m => m.LogsToDelete [i]。已检查,新的{@class =“ checkbox”})@ Html.HiddenFor(m => m.LogsToDelete [i] .LogID)

I ended up making a class that held two item; 我最后做了一个有两个项目的课。 an int for the ID of the item to delete, and a bool to store the .checked value of the checkbox. 用于删除项目ID的int以及用于存储复选框的.checked值的布尔值。 Before the page loads I make a list of objects of my "logsToDelete". 在页面加载之前,我列出了“ logsToDelete”的对象列表。 Then use this to determine which logs to delete in the post. 然后使用它来确定要在帖子中删除的日志。 thanks guys. 多谢你们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 字符串未被识别为有效的布尔值 - String was not recognized as a valid boolean 查看生成错误消息:字符串未被识别为有效的布尔值 - View generating error message: String was not recognized as a valid Boolean 字符串在排序时未被识别为有效布尔值 - String was not recognized as a valid boolean on sorting SqlConnectionStringBuilder-无法将字符串识别为有效的布尔值 - SqlConnectionStringBuilder - String was not recognized as a valid Boolean 字符串“Sunday”未被识别为有效 Boolean - String "Sunday" was not recognized as a valid Boolean 使用checkboxes-string删除datagridview中的多行未识别为有效的布尔值 - Deleting multiple rows in datagridview using checkboxes-string was not recognized as a valid boolean 查询给出错误:字符串未被识别为有效的布尔值 - Query gives error: String was not recognized as a valid Boolean System.FormatException:字符串未被识别为有效的布尔值 - System.FormatException: String was not recognized as a valid Boolean 附加信息:字符串未被识别为有效的布尔值 - Additional information: String was not recognized as a valid Boolean 在C#RadioButton中,字符串未被识别为有效的布尔值 - String was not recognized as a valid boolean in C# RadioButton
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM