简体   繁体   中英

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.

<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. 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. But with the "i" it throws this error. 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.

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

@Html.CheckBoxFor(m => m.LogsToDelete[i].Checked, new { @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. Before the page loads I make a list of objects of my "logsToDelete". Then use this to determine which logs to delete in the post. thanks guys.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM