I am using a simple for loop like this to output a table of images stored in a database:
@for(var i = 1; i < 7; i++){
<tr>
<td>Image @i:</td>
<td><img src="images/@image01" /></td>
</tr>
}
What I want to do is to use the i variable in the image field name as well because in the above example, obviously each image is the same, coming from the image01 field. I tried the following but it doesn’t work. Does anyone know the correct way to code this?
@for(var i = 1; i < 7; i++){
<tr>
<td>Image @i:</td>
<td><img src="images/@image0@i" /></td>
</tr>
}
I’ve tried various things but I’m just learning razor syntax coming from ASP Classic so I’m just guessing at the moment.
Cheers,
Kev
If image01 is a field, you can’t dynamically create a variable name, you have to do:
The only other option is reflection, but I don’t how how that is done in a Razor view.