vendredi 3 juillet 2020

Checkboxes in ASP.NET 5 forms: for-loop is too slow, but foreach doesn't check properly

I still haven't upgraded to .NET Core, and I am trying to render a list of checkboxes for my ViewModel collections in ASP.NET MVC. I read (here: Multiple checkboxes in razor (using foreach)) that one cannot use a foreach loop to generate the checkboxes, because it will not bind the values correctly. However, the proposed solution of using a standard for-loop is way too slow:

@for(int i = 0; i < Model.Prop.Count; i++)
{
  <tr>
    <td class="js-export-checkbox">
      @Html.CheckBoxFor(m => m.Prop[i].IsChecked)
    </td>
  </tr>
}

So what am I supposed to do? Is there simply no solution here? I either forget on having properly checked boxes, or else I let my application take way too long to load?

Any help would be appreciated.




Aucun commentaire:

Enregistrer un commentaire