How to add a razor value and a string in an HTML attribute?

I know it's simple and I am probably missing something...Assume I want to give IDs to generated controls, when my model is a list of integers:

@model List<Int>
...
foreach(int number in Model)
{
   <div id="box + @number"></div>
}
...

box + @number actually gives me : id="box + 1", "box + 2", etc. When I want : "box1", "box2". What am I doing wrong?

Upvotes: 7

Views: 9259

Answers (1)

Martin Booth
Martin Booth

Reputation: 8595

try:

<div id="@("box"+number)"></div>

Upvotes: 20

Related Questions