Kendo UI ListView Template in MVC4 -
i trying image files database , bind kendoui listview. problem is not showing images @ all.
this have done:
view
<script type="text/x-kendo-tmpl" id="template"> <div class="product"> <img src="@url.content("#:photoid# + #:mimetype#")" /> </div> </script> <div id="imagelistview2" class="demo-section"> @(html.kendo().listview<worcestermarble.viewmodels.photosviewmodel>() .name("listview") .tagname("div") .clienttemplateid("template") .datasource(datasource => { datasource.read(read => read.action("getimages", "stockreceiptsgrid").data("passstockidtolistview")); datasource.pagesize(1); }) .pageable() .selectable(selectable => selectable.mode(listviewselectionmode.multiple)) //.events(events => events.change("onchange").databound("ondatabound")) ) </div>
controller
public jsonresult getimages([datasourcerequest] datasourcerequest request, int stockreceiptid) { var photos = _stockphotosrepository.getstocreceiptkphotos(stockreceiptid).tolist(); var photoslist = new list<photosviewmodel>(); //var photoslist = new list<filecontentresult>(); if (photos.count != 0) { foreach (var stockphoto in photos) { var photovm = new photosviewmodel(); photovm.photoid = stockphoto.photoid; photovm.image = stockphoto.imagedata; photovm.mimetype = stockphoto.mimetype; // filecontentresult file = file(stockphoto.imagedata, stockphoto.mimetype); photoslist.add(photovm); } return json(photoslist.tolist(), jsonrequestbehavior.allowget); } else { return null; //filepathresult file = this.file("/content/images/80.jpeg", "image/jpeg"); //return file; } return null; }
photo view model:
public class photosviewmodel { public int photoid { get; set; } public byte[] image { get; set; } public string mimetype { get; set; } public int stockreceiptid { get; set; } }
i not sure if problem caused image url setting in template. see not url because image not saved anywhere except database. screenshot of how listview looks like; blank though there must 15 images displayed!
please let me know clues or solutions problem.
i know bit older, need change line return json(photoslist.tolist(), jsonrequestbehavior.allowget);
following:
return json(photoslist.todatasourceresult(request), jsonrequestbehavior.allowget);
if method todatasourceresult
not recognized, have add
using kendo.mvc.extensions;
on top of document.
Comments
Post a Comment