我正在使用webGrid来显示数据。两列是复选框。我没有显示复选框,而是显示两个.png图像。
正如您在代码中看到的那样,我尝试了三种不同的方法。
我创建了一个变量来保存路径,我使用了string.Format,并且我还将路径作为参数放在Html.Raw中。他们都没有工作。
我还在images文件夹中添加了一个Web.config文件,但它似乎也没有。
我错过了什么吗?我怎样才能使它发挥作用?
我感谢你的帮助。
@{
var checkboxEmpty = "<img src=\"~/Modules/Mime.Picor/Content/images/CheckboxEmpty.png\" />";
var grid = new WebGrid(Model, canPage: false);
}
<div>
@grid.GetHtml(
tableStyle: "table table-striped table-condensed table-hover table-bordered",
headerStyle: "success",
columns: grid.Columns(
grid.Column("Name", format: (item) => Html.ActionLink((string)item.Name, "Details", "LoadList", new { id = item.Id }, null)),
grid.Column("DateIssued", header: "Issued Date", format: (item) => item.DateIssued.ToShortDateString()),
grid.Column("DateRevised", header: "Revised Date", format: (item) => item.DateRevised == null ? "" : item.DateRevised.ToShortDateString()),
grid.Column("DateSchedShip", header: "Schedule Ship Date", format: (item) => item.DateSchedShip == null ? "" : item.DateSchedShip.ToShortDateString()),
grid.Column("TruckingCompany", header: "Trucking Company"),
grid.Column("Comments", header: "Special Instructions", style: "col-lg-2"),
grid.Column("Complete", header: "Cmp", format: (item) =>
{
if (item.Complete == 1)
{
return Html.Raw(string.Format("<text><img src=\"{0}\" alt=\"Image\"/></text>", Url.Content("~/Modules/Mime.Picor/Content/images/CheckboxFull.png")));
}
else
{
return Html.Raw(checkboxEmpty);
}
}, style: "text-align-center"),
grid.Column("MakeReady", header: "Mk. Rdy", style: "text-align-center", format: (item) => (item.MakeReady == 1) ? Html.Raw("<img src='~/Content/images/CheckboxFull.png' />") : Html.Raw("<img src='~/Content/images/CheckboxEmpty.png' />")),
grid.Column("AllDistributors", header: "Distributors", canSort: false, style: "col-lg-4"),
grid.Column("DEL", format: (item) => Html.ActionLink("Delete", "Delete", "LoadList", new { id = item.Id }, new { @class = "delete16image" }))
))
以下是图片路径的呈现HTML:
<text>
<img src="~/Modules/Mime.Picor/Content/images/CheckboxEmpty.png></img>
</text>