如何在webgrid中显示图像

时间:2016-02-23 10:12:24

标签: asp.net-mvc razor webgrid

我需要在webgrid的列中显示图像。使用从控制器返回的列表填充Webgrid。我分别在视图和控制器中使用了以下代码:

@using (Html.BeginForm(null, null, FormMethod.Post ))
{

<div id ="DivGrid">
    @{
        WebGrid grid = new WebGrid(source: Model);
        @grid.GetHtml(htmlAttributes: new { id = "DataTable" }, columns: grid.Columns(
        grid.Column(format: @<img src="@Href("vPath")"/>),
        grid.Column("title","Product Name"),
        grid.Column("user_ID","User ID"),
        grid.Column("", format: @<text>@Html.ActionLink("Edit", "EditOrder", "OrderStatus", new { id = item.ID})</text>)));
      //  grid.Column("", format: @<text>@Html.ActionLink("Delete", "DeleteOrder", "OrderStatus", new { id = item.ID}, new { onclick = "return confirm('Are you sure you wish to delete this Order status?');" })</text>)));          
        }

</div>



using (APM context = new APM())
            {
                lstorder = (from s in context.T_Order
                            join p in context.T_OrderDetails on s.ID equals p.Order_ID
                            join t in context.T_OrderDetailSpecification on p.ID equals t.OrderDetails_ID

                            join r in context.M_Product on p.Product_ID equals r.ID
                            where  s.OrderStatus_ID == 1 && p.IsPreviewRequired == 1 && p.OrderStatus_ID == 1

                            select new orderList
                            {
                                ID = p.ID,
                                vPath = r.VirtualPath,
                                product_ID = r.ID,
                                title = r.Title,
                                amount = t.Value,
                                user_ID= (int)s.User_ID,
                                sel_ID= (int)p.SelectionList_ID

                            }).ToList();

 return View(lstorder);
            }

但代码&#39; grid.Column(format: @<img src="@Href("vPath")"/>),&#39;不显示图像。只是显示类似/ views / PreviewRequest / vPath

的路径

1 个答案:

答案 0 :(得分:0)

试试这个:

我改变了

grid.Column(format: @<img src="@Href("vPath")"/>) 

grid.Column(format: @<img src="@Href(item.vPath)"/>),