Kendo Column with Server Image

I have a Kendo grid that displays images in a column correctly if the images are stored on my machine.

@(Html.Kendo().Grid<ProjectName.Models.SomeModel>() .Name("grid") .Columns(columns => { ... columns.Bound(c => c.Image).ClientTemplate("<img src='c:/pics/" + "#=Image#' alt='image' Title='image' height='24'/>").Title("Image"); }) 

So, this correctly displays the images that are stored on my local hard drive in the path c:/pics . But now I need to show the images that are stored on a specific server, and not on the c:/pics folder on my machine.

I tried replacing this bit here:

 src='c:/pics/" 

with these options:

 src='\\999.99.99.999\ProjectName\Images\' src='\\\\999.99.99.999\\ProjectName\\Images\\' src='http://999.99.99.999/ProjectName/Images/' src='999.99.99.999/ProjectName/Images/' 

But none of them work.

* Please note that 999.99.99.999 is fictitious, I insert the real IP address there.

How to set the image source for the IP address of another computer?

EDIT:

If I have an image tag in any other part of the View, it works fine, for example:

 <img src="\\999.99.99.999\ProjectName\Images\somepic.jpg" alt="whatever" /> 

But inside the ClientTemplate for a column in the grid, I get backslash errors, so I also tried double backslashes.

+1
source share
1 answer

You tried to pull javascript so something like this might work for you:

From this:

 columns.Bound(c => c.Image).ClientTemplate("<img src='c:/pics/" + "#=Image#' alt='image' Title='image' height='24'/>").Title("Image"); 

To that:

 columns.Bound(c => c.Image).ClientTemplate("#=GetMyImage(data.Image)#").Title("Image"); 

Then you have a javascript function that creates the image for you.

 <script> function GetMyImage(image) { var returnString = 'No Image Found'; //just checking to see if we have a name for the image if(image !== null && image.length > 0) { returnString = '<img src="{Your server details here}\" + image + '" title="image" height="24" alt="image"/>; return returnString; } } </script> 

This is usually what I do if I want to do something more creative with a client template for Kendo networks.

+1
source

Source: https://habr.com/ru/post/973039/


All Articles