FileManager read results not binding

2 posts, 1 answers
  1. Doran
    Doran avatar
    2 posts
    Member since:
    Jun 2020

    Posted 07 Jun 2020 Link to this post

    I am trying to get a basic FileManager widget working in our app, but cannot get a remote data bind working correctly.  

    My Javascript looks like this:

    createFileManager: function () {
        $("#fileManager").kendoFileManager({
            dataSource: {
                schema: kendo.data.schemas.filemanager,
                transport: {
                    read: {
                        url: "myController/Read/",
                        method: "POST"
                    },
                },
                change: function (e) {
                },
                error: function (e) {
                },
            },
            toolbar: {
                items: [
                    { name: "sortDirection" },
                    { name: "sortField" },
                    { name: "changeView" },
                    { name: "spacer" },
                    { name: "details" },
                    { name: "search" }
                ]
            },
            draggable: true,
            resizable: true,

            dataBound: onDataBound

        });
    },

     

    And my controller code is thusly:

    // borrowed from Kendo service example...
    public class FileManagerEntry
    {
        public string Name { get; set; }
        public long Size { get; set; }
        public string Path { get; set; }
        public string Extension { get; set; }
        public bool IsDirectory { get; set; }
        public bool HasDirectories { get; set; }
     
        public DateTime Created { get; set; }
        public DateTime CreatedUtc { get; set; }
        public DateTime Modified { get; set; }
        public DateTime ModifiedUtc { get; set; }
     
        public IEnumerable<FileManagerEntry> Directories { get; set; }
    }
     
    // CONTROLLER snippet....
    public JsonResult Read(string target)
    {
        var content = GetContent();
     
        var result = content
            .Select(f => new
            {
                name = f.Name,
                size = f.Size,
                path = f.Path,
                extension = f.Extension,
                isDirectory = f.IsDirectory,
                hasDirectories = f.HasDirectories,
                created = f.Created,
                createdUtc = f.CreatedUtc,
                modified = f.Modified,
                modifiedUtc = f.ModifiedUtc
            });
     
        return Json(result, JsonRequestBehavior.AllowGet);
    }
     
    // Hardcoded data for testing...
    private IEnumerable<FileManagerEntry> GetContent()
    {
        return new List<FileManagerEntry>
        {
            new FileManagerEntry
            {
                Name = "Folder",
                Size = 0,
                Path = "folder",
                Extension = "",
                IsDirectory = true,
                HasDirectories = false,
                CreatedUtc = DateTime.UtcNow,
                Created = DateTime.Now,
                ModifiedUtc = DateTime.UtcNow,
                Modified = DateTime.Now
            },
            new FileManagerEntry
            {
                Name = "Image.jpg",
                Size = 20,
                Path = "folder/Image.jpg",
                Extension = ".jpg",
                IsDirectory = false,
                HasDirectories = false,
                CreatedUtc = DateTime.UtcNow,
                Created = DateTime.Now,
                ModifiedUtc = DateTime.UtcNow,
                Modified = DateTime.Now
            },
            new FileManagerEntry
            {
                Name = "Image2.jpg",
                Size = 20,
                Path = "folder/Image2.jpg",
                Extension = ".jpg",
                IsDirectory = false,
                HasDirectories = false,
                CreatedUtc = DateTime.UtcNow,
                Created = DateTime.Now,
                ModifiedUtc = DateTime.UtcNow,
                Modified = DateTime.Now
            }
        };
    }

     

    Most of the code, I cobbled together from the Kendo examples for FileManager. 

    When I run my app....  The FileManager renders & the FileManager dataBound event fires.  But the three objects in the manager are all undefined.  I jave attached screengrabs of the filemanager.datasource and also the file "details" as shown by FileManager. 

    i do not know why the data isn't binding appropriately.  Is this a problem with the results coming from my controller?  

    Appreciate any help.

     

     

     

  2. Answer
    Ianko
    Admin
    Ianko avatar
    1945 posts

    Posted 09 Jun 2020 Link to this post

    Hello Doran,

    I suspect you are referencing the kendo.aspnetmvc.js file in your application and the schema for the FileManagerDataSource needs pascal case fields in order to work properly. 

    You can try by directly feeding the content instead of the mapped result: 

    public JsonResult Read(string target)
    {
        var content = GetContent();
    
     
        return Json(content, JsonRequestBehavior.AllowGet);
    }

    I hope this will solve the case.

    Regards,
    Ianko
    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
Back to Top