Combining code and text in an HTML attribute using Razor

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

 @foreach (var item in Model) { <div class="grid_6 listColumn" id=" team_@item.TeamID "> ... </div> } 

Basically, I want div identifiers to be marked with an icon in item.TeamID , for example:

TEAM_1 TEAM_2 team_3

The syntax that I have does not recognize part of the code. I also tried id=" team_@ :item.TeamID" , but it throws an error. However, id="team_ @item.TeamID" works fine, but I don't want this place there. I'm new to Razor, is there an easy way to do this?

+4
source share
1 answer

Try the following:

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

Source: https://habr.com/ru/post/1391970/


All Articles