Can I use a for
loop to show the model view list? Or do I have to use foreach
?
If yes, can anyone show me an example please? Thank you.
@model IList<TestMVC1.Models.Account>
@{
ViewBag.Title = "Index";
}
<h2>Accounts List</h2>
@{var student = ViewBag.AccoutList; }
@for (int i = 0; i < student.Count; i++)
{
<div>@student[i].CounterID</div>
<div>@student[i].AccountID</div>
<div>@student[i].AccountName</div>
}
@foreach (var item in Model)
{
<div>@item.CounterID</div>
<div>@item.AccountID</div>
<div>@item.AccountName</div>
}
I want to use it with for
loop not foreach
but it's not working! I mean the model not the viewBag
@for (int i = 0; i < Model.Count ; i++)
{
<div>@model[i].CounterID</div>
<div>@model[i].AccountID</div>
<div>@model[i].AccountName</div>
}