2016-08-13 67 views
0

我有一个格是这样的:如何添加图片列到剑道UI电网

@(Html.Kendo().Grid<ProductViewModel>() 
    .Name("Grid") 
    .Columns(columns => 
    { 
     **columns.Bound(c => c.Logo).ClientTemplate();** 


     columns.Bound(p => p.Title); 
     columns.Bound(p => p.Category); 
     columns.Bound(p => p.SupplierName); 
     columns.Bound(p => p.SupplierContactName); 
     columns.Bound(p => p.IsDeleted); 
     columns.Bound(p => p.TimeStamp).Format("{0:yyyy/MM/dd HH:mm}").EditorTemplateName("DateTime"); ; 
     //columns.Command(command => { command.Edit(); command.Destroy(); }).Width(220).Title("Command"); 
     //columns.Command(command => { command.Edit(); command.Destroy(); }).Width(250); 
    }) 
    .Pageable() 
    .Scrollable() 
    .DataSource(dataSource => dataSource 
     .Ajax() 
     .PageSize(20) 
     .Events(events => events.Error("error_handler")) 
     .Model(model => model.Id(p => p.ID)) 
     .Read(read => read.Action("EditingCustomValidation_Read", "Product")) 

    ) 

而且我有这样一个行动显示图像:

public FileContentResult Photo(int id) 
{ 
    return new FileContentResult(db.Products.Find(id).Logo, "image"); 
} 

我应该写我用于调用此动作的ClientTemplate发送productid显示产品徽标?

回答

0

请你可以尝试这样的...

columns.Bound(c => c.Logo).ClientTemplate("<img src='" + Url.Content("~/ImagePath/") + "#=ImageUrl#' alt='#=Name #' Title='#=Name #' height='62' width='62'/>"); 
0

我的一位同事遇到了同样的问题,我们在telerik论坛Bind image path to a controller function in Kendo Grid上发布了问题,他们回复如下。

我认为,而不是你的控制器返回一个字符串与图像的URL,它可能会更容易它只是返回图像本身。像this post on stackoverlow

这样,你可以让你的模板指向img html元素的src属性到这个控制器动作,这大概需要作为参数来查找相应的图像文件到每个行元素。