开发者

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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜