I have been stuck on this for some time now; I’m using ASP.NET MVC 4 and C# for a web application. I read in an Excel file from my controller, and I have a List of all the cells which I send back to my view. This is what I’m using:
<table>
@foreach (var item in ViewBag.range)
{
<tr>
@for (int i = 0; i < 6; i++)
{
<td>
<input style="width:50px;" value=@item />
</td>
}
</tr>
}
</table>
Basically, I have 6 columns in Excel. I am trying to recreate the Excel in my view.
But there is something wrong with my for loop, it’s doing each cell 6 times.
Can anyone help please?
It does that because you tell it to in the
forloop. Perhaps you should remove it.EDIT
This will place the items inside of
rangeinto rows which have 6 columns each.