2016-08-13 68 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屬性到這個控制器動作,這大概需要作爲參數來查找相應的圖像文件到每個行元素。