Kendo Upload - Pass in other parameter of Model to custom template

4 posts, 0 answers
  1. lucerias
    lucerias avatar
    16 posts
    Member since:
    Nov 2011

    Posted 27 Jan Link to this post

    Hi,

    I have fileObjects and it has properties (name, extension, size, filepath). I understand name, extension and size are the reserved keywords that can be used in template code. However, i need the filepath (additional parameter) to be passed and used in template code.

    So that when user click on the hyperlink, it will call the download function with two parameter (path and name). File path is mandatory because each file is stored in respective unique id (folder name) folder.

    <% List<FileModel> files = ViewBag.files; %>
    var fileObjects = <%: Html.Raw(Json.Encode(files)) %>
     
    $("#upload-file").kendoUpload({
        async: {
            saveUrl: "<%: Url.Action("UploadFile", ViewBag.Controller, new { topicId = Model.Id }) %>",
            removeUrl: "<%: Url.Action("RemoveFile", ViewBag.Controller, new { topicId = Model.Id }) %>",
            autoUpload: true
        },
        template:
            "<span class='k-progress' style='width: 100%;'></span>" +
            "<span class='k-icon k-i-doc'></span>" +
            "<span class='k-filename' title='#=name#'><a href='\\#' onclick='downloadFile(\"#=name#\")'>#=name#</a></span>" +
            "<strong class='k-upload-status'>" +
                "<button type='button' class='k-button k-button-bare k-upload-action'>" +
                    "<span class='k-icon k-i-close k-delete' title='Remove'></span>" +
                "</button>" +
            "</strong>",
        files: fileObjects,
        success: onSuccess,
        error: onError,
        upload: onUpload
    });

     

    Thanks.

    Regards,
    Yap Hui Hong

  2. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2153 posts

    Posted 29 Jan Link to this post

    Hello,

    Indeed at the moment only name, size and extension are passed as template data for the files. A possible resolution for the current case would be to add an element in the template for displaying the path and manually populate it after the widget is rendered. Here is a sample implementation that demonstrates the mentioned approach.

    Regards,
    Dimiter Madjarov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. Kendo UI is VS 2017 Ready
  4. Kevin F
    Kevin F avatar
    46 posts
    Member since:
    Sep 2009

    Posted 27 May in reply to Dimiter Madjarov Link to this post

    It would be very helpful to have the UID passed in to the template as well.  I'm trying to implement a template where the user can click on a file name inside the upload control to view it.  Since the files in this case are stored in the database, having the UID available would be very convenient!
  5. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2153 posts

    Posted 29 May Link to this post

    Hello Kevin,

    Thank you for the feedback. We will consider it for future versions. At the moment you could access the uid in the click handler you are implementing, by accessing the current file list item and it's data-uid attribute.

    Regards,
    Dimiter Madjarov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
Back to Top
Kendo UI is VS 2017 Ready