MvcContrib基于模型值的网格条件单元格格式

时间:2011-01-23 14:34:30

标签: mvccontrib-grid

我需要根据模型中的布尔值条件格式化单元格值。 我有列col.For(item => item.Detail); 如果item.Unfinished我需要应用一些CSS样式 我怎么能这样做?

2 个答案:

答案 0 :(得分:9)

答案在我对原帖的评论中:

http://groups.google.com/group/mvccontrib-discuss/browse_thread/thread/f872d298cc9d53dc

column.For(x => x.Surname).Attributes(x => {
    if(x.Item.Surname == "foo") {
        return new Dictionary<string, object> { { "style", "color:red"} };
    }
    return new Dictionary<string, object>();
});

答案 1 :(得分:3)

如果您仍在寻找解决方案:

” MVCContrib网格的上述属性也可以解决问题。

<%= Html.Grid(Model.Services).AutoGenerateColumns()
    .Columns(column => {
        column.For(a => Html.ActionLink("Editar", "Edit", new { id = a.Id }))
            .InsertAt(0).Encode(false)
            .CellCondition(x => 
                (x.CreatedBy==Membership.GetUser().UserName));
    })
    .Sort(Model.GridSortOptions)
    .Attributes(@class => "table-list")
    .Empty(Resources.NO_DATA_TO_DISPLAY)
%>

杰里米斯金纳的信誉 http://www.jeremyskinner.co.uk/2010/04/27/mvccontrib-grid-part-7-auto-generated-columns/comment-page-1/#comment-19059

和最初在这里发布的jpassos: http://forums.asp.net/p/1559843/3850767.aspx