结合code和文本在HTML属性与剃刀 [英] Combining Code and Text in HTML Attribute with Razor
问题描述
我创建了一堆&LT的; DIV>
使用剃刀语法的foreach
循环元素。现在,我有这样的:
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="team_@item.TeamID">
...
</div>
}
基本上我想由值 item.TeamID
标记像DIV的标识符:
Basically I want the div identifiers to be labeled by the value in item.TeamID
like:
TEAM_1
TEAM_2
team_3
team_1 team_2 team_3
语法我现在有不认code部分。我也试过 ID =团队_ @:item.TeamID
,但它抛出一个错误。然而, ID =team_ @ item.TeamID
工作正常,但我不想在那里的空间。我是pretty新的剃刀,有一个简单的方法来做到这一点?
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?
推荐答案
试试这个:
<div class="grid_6 listColumn" id="@("team_" + item.TeamID)">
...
</div>
这篇关于结合code和文本在HTML属性与剃刀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!