Alon Shmiel
Alon Shmiel

Reputation: 7121

set different ids inside for loop

I want to set different ids.

The first one will be: id1

the second: id2.

till ths last: id6.

how can I do that?

@for (int i = 0; i < 7; i++) {
    <img id="id + @i" src="img.jpg">
}

Upvotes: 0

Views: 81

Answers (2)

agarici
agarici

Reputation: 612

Try this: Just use a loop for i = 1 to 6:

@for (int i = 1; i <= 6; i++) {
    <img id="id + @i" src="img.jpg">
}

Upvotes: 0

gzaxx
gzaxx

Reputation: 17590

Try that:

@for (int i = 0; i < 7; i++) {
    <img id='@("id" + i)' src="img.jpg">
}

Upvotes: 3

Related Questions