我目前有这段代码
@if(true) { <text> <td class="add"></td> </text> } else { <text> <td class="remove"></td> </text> }
我想改用这样的东西
<td> @if(true) { <text> @class="add" </text> } else { <text> @class="remove" </text> }</td>
我不确定这是正确的,还是正确的语法
答案 0 :(得分:0)
@functions {
object getAttributes(bool val)
{
if (val)
{
return new {@class="add"};
}
return new { @class="remove"};
}
}
<td>
@Html.TextBoxFor(model => model.FirstName,@getAttributes(style))
@getAttributes(style)
<td>