mardi 4 avril 2017

Checkbox adds extra "false" value per selected one

I have this piece of code in my View which belongs to a form

<div class="col-md-10">
@foreach (var l in leads)
{
    @: @Html.CheckBox("cbLead", false, new { @value = @l.Id }) @Html.TextBox("worth", "") - @Html.Label(l.Name)
}
</div>

And this is the form with I handle the post:

[HttpPost]
public ActionResult Update(string[] cbLead, double[] worth)
{
    // code
}

I have 24 checkboxes, but for each checkbox selected I receive 2 values in the Update method. So for example if I select 3 out of that 24 checkboxes, I receive 27 values in the string[] cblead.

Example with 24 checkboxes:

3 first checkboxes selected

And this is what I get in the method:

enter image description here

So I receive the value checked and an added false after. Any tips?




Aucun commentaire:

Enregistrer un commentaire