How to bind images in Telerik Grid for ASP.NET MVC

谁说胖子不能爱 提交于 2019-12-02 12:13:01

This is possible by adding another templated column to your collection:

Using ASPX

columns.Template(c => { 
%><img alt="Static Image Alt Text" src="<%= Url.Content("~/myImage.jpg") %>" 
/><% 
}).Title("Static Image");

Using Razor

columns.Template(
   @<text>
     <img alt="Static Image Alt Text" src="@Url.Content("~/myImage.jpg") " />
  </text>
).Title("Static Image");

UPDATE: If you wish to bind images from your model, please refer to the following example:

columns.Template(c => {
%>
<img 
alt="<%= c.CustomerID %>" 
src="<%= Url.Content("~/" + c.CustomerID + ".jpg") %>" 
/>
<%
});

Or if you're using client templates, try the following:

.Columns(columns =>
{
columns.Bound(c => c.CustomerID)
.ClientTemplate("<img alt='<#= CustomerID #>' src='" 
+ Url.Content("~/") 
+ "<#= CustomerID #>.jpg' />")
.Title("Picture");
//omitted for brevity
}

This way we can bind image with every row. we can also add Action with these images.

columns.Command(commands => commands.Custom("View").ButtonType(GridButtonType.BareImage)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!