Why is there an extra value in the array and how can I fix this?

Viewed 38

I'm currently working on a project for school where I take information from a MySQL server and display it on a webgridview where I can then edit, insert, and delete information. There is currently a column that is giving me an issue. This column appears as a check box to indicate an active or inactive record. The values in the column will then be inserted into an array.

If I put breaking points in my code and check the array I can see an extra value is always added in right before the last value on the grid. For example if I have two grid values going {false, true} I can see in the array three values of {false, false, true}. If I have three grid values of {true, true, true} I can see four in the array of {true, true,false,true}. I've debugged and think I narrowed down the issue to one line of code inside the webgrid column with the check box here.

MySQLTabGrid.Column("Status","Status", format: (item) => Html.CheckBox("status”,(bool)item.status),

If I update the "HTML.CheckBox" to "HTML.TextBox" the extra value goes away. Why is this? What could cause an extra value to be inserted and how can I fix it. Here is my code on the view modelBinder that separates each column to insert into the array. Since I am new to C# and razor would there be a better way to do it?

string[] status = request.Form["status"].Split(',');

0 Answers
Related