0

在我看来,我正在使用这个 webgrid。

 <div class="grid">
 @{
var grid = new WebGrid(Model.SearchResults, canPage: true, rowsPerPage: 15);
grid.Pager(WebGridPagerModes.NextPrevious);
 @grid.GetHtml(
           htmlAttributes: new { @style = "width:100%", cellspacing = "0" },
           columns: grid.Columns(
           grid.Column(header: "Customer Name", format: (item) => Html.ActionLink((string)item.FullName, "ShowContracts", new { id = item.UserId }, new { @style = "color: 'black'", @onmouseover = "this.style.color='green'", @onmouseout = "this.style.color='black'" })),
           grid.Column(header: "SSN", format: item => item.SSN)
))
}
</div>

我使用 SSN 搜索并在 webgrid 中显示结果。显示的数据是虚拟数据。我的视图模型中有一个 bool AccountVerified,现在我不应该为未验证的帐户提供操作链接,并在它们旁边显示说明帐户验证待定的文本。有人可以帮我吗?

4

1 回答 1

3

尝试以下操作:

grid.Column(
    header: "Customer Name", 
    format: (item) => 
        (bool)item.AccountVerified 
            ? Html.ActionLink(
                  (string)item.FullName, 
                  "ShowContracts", 
                  new { 
                      id = item.UserId 
                  }, 
                  new { 
                      style = "color: 'black'", 
                      onmouseover = "this.style.color='green'", 
                      onmouseout = "this.style.color='black'" 
                  }
              ) 
            : Html.Raw("pending")
)

或者编写一个自定义的 HTML 帮助程序来避免这种怪物,并且简单地:

grid.Column(
    header: "Customer Name", 
    format: item => Html.PendingLink(item)
)
于 2011-08-04T14:06:13.477 回答