Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 970
Evangelos Aktoudianakis Avatar asked Jun 03 '14 00:06

Evangelos Aktoudianakis


1 Answers

try:

<div id="@("box"+number)"></div>
like image 84
Martin Booth Avatar answered Oct 16 '22 13:10

Martin Booth