How to use @if{} blocks with razor to build the equivalent of the following ? : inline code?
How could I use @if blocks to build the equivalent of this ? : inline code? Thx!
grid.Column("Name", "Name", format: @<text>
<div
style='color: @(@item.Name == "Bill") ? "black" : "red") '
>
@item.开发者_运维技巧Name
</div>
</text>),
How about externalizing this logic into a partial to avoid the mess:
grid.Column("Name", "Name", format: @Html.Partial("_item", item))
and then inside your _item.cshtml
partial do whatever ifs you want or even better use HTML helper:
@model ItemViewModel
<div style="@Html.StyleForItem(item)">
@Html.DisplayFor(x => x.Name)
</div>
精彩评论