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

1 Answer 1

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>)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.