I have ViewBag
which can have a count of one or two. If the count is one then I want some set of Html to repeat else if the count is two then I want the loop to execute normally.
for(int i = 0; i < ViewBag.Address; i++)
{
if(i== 0) {
<b>Current Address</b>
}
else{
<b>Permanent Address</b>
}
<input type="text" value="@ViewBag.Address[i].Addreess1" />
<input type="text" value="@ViewBag.Address[i].Addreess1" />
//I tried doing something like
i = ViewBag.Address.Count == 1 ? 0: 1;
}
But here the loop keeps on repeating is there anyway to check if the count is one then repeat the loop again else continue rendering as per the items within ViewBag.
Can't You just move this statement:
inside for loop like this?