Getting ArgumentOutOfRangeException using for loop in Blazor component

前端 未结 2 1673
伪装坚强ぢ
伪装坚强ぢ 2020-12-22 12:27

I\'m trying out Blazor and I\'m getting this exception when I\'m trying to load a list of checkboxes using a for loop.

I\'ve created the list here:

p         


        
2条回答
  •  有刺的猬
    2020-12-22 13:08

    I prefer to use a foreach statement in this case :

    @foreach(var month in _months)
    {
        
    } @code { private IEnumerable _months; protected override void OnInitialized() { _months = new List { new Month{ MonthId = 0, MonthName = "All Months", IsMonthChecked = false }, new Month{ MonthId = 1, MonthName = "Jan", IsMonthChecked = false }, new Month{ MonthId = 2, MonthName = "Feb", IsMonthChecked = false }, new Month{ MonthId = 3, MonthName = "Mar", IsMonthChecked = false }, new Month{ MonthId = 4, MonthName = "Apr", IsMonthChecked = false }, new Month{ MonthId = 5, MonthName = "May", IsMonthChecked = false }, new Month{ MonthId = 6, MonthName = "Jun", IsMonthChecked = false }, new Month{ MonthId = 7, MonthName = "Jul", IsMonthChecked = false }, new Month{ MonthId = 8, MonthName = "Aug", IsMonthChecked = false }, new Month{ MonthId = 9, MonthName = "Sep", IsMonthChecked = false }, new Month{ MonthId = 10, MonthName = "Oct", IsMonthChecked = false }, new Month{ MonthId = 11, MonthName = "Nov", IsMonthChecked = false }, new Month{ MonthId = 12, MonthName = "Dec", IsMonthChecked = false } }; base.OnInitialized(); } }

提交回复
热议问题