Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combining Code and Text in HTML Attribute with Razor

I am creating a bunch of <div> elements using a foreach loop with Razor syntax. Right now I have this:

@foreach (var item in Model)
{
    <div class="grid_6 listColumn" id="[email protected]">
    ...
    </div>
}

Basically I want the div identifiers to be labeled by the value in item.TeamID like:

team_1 team_2 team_3

The syntax I currently have doesn't recognize the code portion. I also tried id="team_@:item.TeamID" but it throws an error. However, id="team_ @item.TeamID" works fine, but I don't want that space in there. I'm pretty new to Razor, is there an easy way to do this?

like image 737
Michael Hornfeck Avatar asked Jan 17 '23 17:01

Michael Hornfeck


1 Answers

Try this:

<div class="grid_6 listColumn" id="@("team_" + item.TeamID)">
    ...
</div>
like image 140
Jacob Avatar answered Feb 16 '23 03:02

Jacob