4

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?

1 Answer 1

10

Try this:

<div class="grid_6 listColumn" id="@("team_" + item.TeamID)">
    ...
</div>
Sign up to request clarification or add additional context in comments.

1 Comment

thanks, that works. also, just came across this post which let me know id="team_@(item.TeamID)" works too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.