mercredi 9 novembre 2016

c# - render list of checkboxes, always returned as checked

Dears,

Please could you help with below problem:

I want to render list of checkbox in my view.

                            @foreach (var test in ViewBag.CF_list)
                            {

                                if (test.Text != "" && test.Text != " ")
                                {
                                     <div class="checkbox">
                                         <label><input value="@test.Value" id="CF_list_" name="CF_list_" @(test.Selected == true ? "checked" : "") type="checkbox"> @test.Text</label>
                                     </div>
                                 }
                            }

OK, checkbox on the page. But problem that - if send this form, at least one of checkboxes all time marked as selected. For example: 1. I selected two chekckboxed, send form - everything is OK. 2. I remove all ticks and send form - one of the checkbox (last clicked) indicated as selected.

Why?

CF_List is SelectListItem




Aucun commentaire:

Enregistrer un commentaire