Html 根据razor中的条件结果分配类
我现在有这个代码Html 根据razor中的条件结果分配类,html,razor,Html,Razor,我现在有这个代码 @if(true) { <text> <td class="add"></td> </text> } else { <text> <td class="remove"></td> </text> } @if(true){}else{} 我想换成这样 <td> @if(true) { <text> @class="add" </text> } e
@if(true) { <text> <td class="add"></td> </text> } else { <text> <td class="remove"></td> </text> }
@if(true){}else{}
我想换成这样
<td> @if(true) { <text> @class="add" </text> } else { <text> @class="remove" </text> }</td>
@if(true){@class=“add”}else{@class=“remove”}
我不确定这是否正确,或者它的语法是否正确{
@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>
对象getAttributes(布尔值)
{
if(val)
{
返回新的{@class=“add”};
}
返回新的{@class=“remove”};
}
}
@Html.TextBoxFor(model=>model.FirstName,@getAttributes(style))
@getAttributes(样式)