ASP.NET MVC 3 WebGrid - 条件列格式

JBi*_*son 7 asp.net-mvc-3

无论如何在ASP.NET MVC 3中使用Webgrid进行条件格式化?

我知道我可以说:grid.Column("PropertyName", "Header Name", style: "bold")......

它将为TD提供HTML,表示:class="bold".

我想要的是用一种风格渲染一些TD,用另一种风格渲染其他TD.像:... grid.Column("PropertyName", "Header Name", style: (item) => (item.Property > 100) ? "bold" : "normal"))....

但这会导致错误"最佳重载方法匹配...有一些无效的参数."

知道这是否可行?

谢谢.Jim Biddison

tor*_*orm 8

我知道我的答案有点迟了,但是如果有人仍然在寻找WebGrid的那种条件格式/列值绑定,那么有些方法可行:

@grid.GetHtml(
   columns: grid.Columns(
      grid.Column(format: (item) => (item.someproperty !=null) ? 
        Html.Raw("I've got value") : 
        Html.Raw("I don't :("))
   )
)
Run Code Online (Sandbox Code Playgroud)


cam*_*inc 5

你可以用一些JQuery来做到这一点:

<script type='text/javascript'>
    $(document).ready(function () {
        jQuery.each($('tbody tr td'), function () {
            if (this.textContent == "some value") {
                $(this).addClass("some class");
            }
        });
    });
</script>
Run Code Online (Sandbox Code Playgroud)

当然,你必须修改每个循环内部的逻辑......

希望有所帮助.