I want to show the image if the item has image, and no image otherwise. Here is my code, but it gets some errors.
So how to use if condition in format parameter of webgrid?
grid.Column("Image", "Ảnh minh họa", format: (item) =>
if(item.Image == null)
{
@<text>Chưa có ảnh minh họa</text>
}
else
{
@<text><img width="50" height="50" src="@Url.Content("~/images/")@item.Image" /></text>
}
, canSort: false)
Edit: I have solved this issue. Here is my code:
grid.Column("Image", "Ảnh minh họa", format: @<text>@if (item.Image == null) { <text>Chưa có ảnh minh họa</text> } else { <text><img width="50" height="50" src="@Url.Content("~/images/")@item.Image" /></text> }</text>
, canSort: false),