Michael Hornfeck
Michael Hornfeck

Reputation: 1252

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?

Upvotes: 4

Views: 2912

Answers (1)

Jacob
Jacob

Reputation: 78840

Try this:

<div class="grid_6 listColumn" id="@("team_" + item.TeamID)">
    ...
</div>

Upvotes: 10

Related Questions