I am creating a pager component and faced a problem. I simplified the code to show the problem :
@for (int i = 0; i < 10; i++)
{
<li @onclick="() =>UpdatePager(i)" class="waves-effect"><a>@(i+1)</a></li>
}
@code{
public void UpdatePager(int iCurPage)
{
Console.WriteLine(iCurPage);
}
}
// when click on 1 console result is 10
// when click on 2 console result is 10
// ...
// when click on 10 console result is 10
My expectation is when I click any of li
s the corresponding number(i
) should be logged in the console but what is actually happen is for all of the li
s the number 10 ( final value of i
) is printed.
What is the problem and how should I pass different values for each rendered elements?