Asp.net MVC3 manipulating WebGrid Row
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
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>)
精彩评论