nemesv's code Conditionally display an image in webgrid - mvc 3 works great in MVC3.
@grid.GetHtml(
displayHeader: false,
columns: grid.Columns(
grid.Column(format: (item) =>
{
if (item.IsMainPreview == true)
{
return Html.Raw(string.Format("<text><img src=\"{0}\" alt=\"Image\"/></text>", Url.Content("~/Content/images/preview-photo.gif")));
}
In MVC4 you don't need Url.Content to use the "~". I haven't been succesful in getting the code to work without the Url.Content (it can't find the image). I have tried
return Html.Raw(string.Format("<text><img src=\"{0}\" alt=\"Image\"/></text>", "~/Content/images/preview-photo.gif"));
and
return Html.Raw(string.Format("<text><img src={0} alt=\"Image\"/></text>", "~/Content/images/preview-photo.gif"));
among others. Does anyone know how to get this to work in MVC4 without the URL.Content?
Thank you,