Multiple checkboxes in razor (using foreach)

后端 未结 3 699
失恋的感觉
失恋的感觉 2020-12-06 13:51

I have a problem and I can\'t find solution. I\'m using Razor and it is my VieModel class.

public class GroupToExport
{
    public GroupToExport()
    {
             


        
3条回答
  •  感动是毒
    2020-12-06 14:08

    I found this works much better: Leave the foreach loop as is (do not user a counter)

    @foreach (var item in Model.GroupToExport)
    {
    

    Then use this Razor format to display a checkbox

    @Html.CheckBox("Active", @item.ToExport)
    

    Simple to use and does not make you change the typical foreach loop.

提交回复
热议问题