10
在我的WebGrid我需要顯示基於價值的圖像..以下有條件顯示的WebGrid圖像 - MVC 3
@model TraktorumMVC.Models.ManagePhotos
@{
ViewBag.Title = "ManagePhotos";
Layout = "~/Views/Shared/_Layout.cshtml";
var grid = new WebGrid(Model.AdPhotos);
}
@grid.GetHtml(
displayHeader: false,
columns: grid.Columns(
grid.Column(format: (item) =>
{
if (item.IsMainPreview == true)
{
return @<text><img src="@Url.Content("~/Content/images/preview-photo.gif")" alt="Image "/></text>;
}
else
{
return @<text><img src="@Url.Content("~/Content/images/non-preview-photo.gif")" alt="Image "/></text>;
}
}
),
grid.Column(format: (item) => Html.ActionLink("Remove Photo", "RemovePhoto", "Images", new { photoID = @item.Id }, new { @class = "RemovePhoto" }))
));
代碼給出我不知道我怎樣才能在使用的WebGrid if
。我只是去嘗試。它的工作不.getting以下錯誤
The best overloaded method match for 'System.Web.Helpers.WebGrid.Column(string, string, System.Func<dynamic,object>, string, bool)' has some invalid arguments
很好,謝謝你的代碼! – juFo
這在MVC3中很有用。您是否知道如何在沒有URL.Content的情況下在MVC4中使用它。我發佈了一個新問題。 http://stackoverflow.com/questions/13711753/conditionally-display-an-image-in-webgrid-mvc-4 – Joe
我投了過去這一個,它只是幫助我一次。如果我可以,我會給你100票! :D –