3
var grid = new WebGrid(source: Model, ...);

grid.Column("IsValid", "IsValid", format: (item) => (item.IsValid) ? 
    ? Html.Raw("< src='../../Content//' />")
    : Html.Raw("< src='../../' />"), style: "testStyle"),

grid.Column(header: "Delete", format: 
    @<text>
        <a href="@Url.Action("Delete", "TestInfo", new { id = item.id })" onclick="javascript:return ConfirmDelete();">
            <img src="../../Content/images/image.png" alt="" style="border:none;" />
        </a>
    </text>, style: "testStyle")

With this code my Delete button appears on every row of the Webgrid. Like the first column, I am trying to impliment the same logic (item) => (item.IsValid) to display the Delete button image if and only if item.IsValid is true.

Can you please suggest how can I accomplish this

shuniar
  • 2,592
  • 6
  • 31
  • 38
DdotP
  • 31
  • 3

1 Answers1

3

I have something like this working where if the current record isn't locked by someone else, the user can edit it as a textbox.

 grid.Column("Volume", "Monthly Vol", format: @<text>@if ((bool)TempData["CanEdit"])
                                                     {
                                                          <input type="text" title="@item.Volume" value="@item.Volume" /> 
                                                     }
                                                     else
                                                     {
        @( item.Volume.ToString())} </text>)

so applied to yours I think it would be

 grid.Column(header: "Delete", format: @<text>@if (item.IsValid)
                                                     {
                                                          <a href="@Url.Action("Delete", "TestInfo", new { id = item.id })" onclick="javascript:return ConfirmDelete();">
        <img src="../../Content/images/image.png" alt="" style="border:none;" />
                                                     }
                                                     else
                                                     {
<span style="display:none"></span>
} </text>)
Maslow
  • 18,464
  • 20
  • 106
  • 193