Using Upload inside Grid

2 posts, 0 answers
  1. Kord
    Kord avatar
    2 posts
    Member since:
    Apr 2018

    Posted 25 Nov 2018 Link to this post

    There is my table:

    public class Sound
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        public Guid GUID { get; set; }
        [Display(Name = "Sound Type")]
        [Required]
        public SoundType SoundType { get; set; }
        [Display(Name = "Bandwidth, kHz")]
        public byte? Bandwidth { get; set; }
        [Display(Name= "Frequency, Hz")]
        public short? Frequency { get; set; }
        [Display(Name = "Duration, ms")]
        public short? Duration { get; set; }
        [Display(Name="Sound File")]
        public byte[] Content { get; set; }
        [Display(Name = "File Name")]
        public string FileName { get; set; }
        public Sound()
        {
            GUID = Guid.NewGuid();
        }
    }

     

    I just would like to show it in a grid and to be possible to upload files into the Content field and to store their names in the FileName field.

    I've been trying to find out some examples of how to perform this, but almost all of them use separated steps to upload files into some directory on the server and to save the path to the file in the table then. I prefer to save the file attributes and its content as one step using Create or Update method of SoundsController.

    Is it possible to do it this way? Are there some examples?

    Thank you.

  2. Marin Bratanov
    Admin
    Marin Bratanov avatar
    4630 posts

    Posted 26 Nov 2018 Link to this post

    Hello,

    If you have a separate view for the editor (e.g., in a custom popup template), you can have an upload there and store all fields in the same POST request. See how to use the uploaded file as a part of the form POST here: https://demos.telerik.com/aspnet-mvc/upload and you can extend the form to contain the rest of the inputs from the model.

    You can find another example in the following code library entry: https://www.telerik.com/support/code-library/upload-in-grid-popup-editor.

    If you will be using any sort of asyncronous file uploads, however, you'd need to store the file and its name somewhere on the server before the actual grid item edit happens, simply because that's an asyncronous operation. You can see how to add metadata to the uploads here so you can take the user ID from the client and send it together wit the file so you can immediately update the data source: https://www.telerik.com/forums/async-kendoupload-pass-custom-arguments-or-additional-data-to-mvc-controller.


    Regards,
    Marin Bratanov
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top