Telerik Forums
UI for ASP.NET MVC Forum
8 answers
168 views
I'm using a strongly-typed partial view for the Grid popup editor and have a couple questions since the upload widget is rendered when the grid's page loads (and therefore there is no real backing model):
  1. How do I specify the initially rendered files using the Files method?
  2. How do I specify a routeValue for the Save and Remove methods based on the model?
If the control was being rendered using the correct model, I'd want the Upload call to look something like:
@(Html.Kendo().Upload()
       .Name("Attachments").Multiple(true).ShowFileList(true)
       .Async(async => async
           .Save("Attach", "Controller", new { entryId = Model.Id })
           .Remove("RemoveAttachment", "Controller", new { entryId = Model.Id }))
       .Files(files => {
           if (Model.Attachments != null)
           {
              foreach (var f in Model.Attachments)
              {
                   files.Add().Name(f);
              }
           }
       }))
Thanks!
Veselin Tsvetanov
Telerik team
 answered on 23 Apr 2019
1 answer
120 views

Hi,

My co-worker sent a excel file to me he just created. I can open it by double clicked file in the folder. But when I try to use Kendo Ul Upload control to select it I got " You don't have permission to open this file. Contact file owner or administrator to obtain permission".  My co-worker said he didn't do any special thing for this file. I checked property - security tab. It same as another file which  I could select it. Could anyone help the issue?

Thanks in advance!

Veselin Tsvetanov
Telerik team
 answered on 16 Apr 2019
1 answer
97 views

Currently evaluating the Upload control, I ideally want only a simple upload button to select local files and do everyting else on my own through the client API.

Especially the gray div (k-widget k-upload k-header) around the button bothers me.

 

My question:

Is it possible to tell the Upload control to simply display the core upload button and omit everything else, even after the user has selected files?

Marin Bratanov
Telerik team
 answered on 26 Dec 2018
1 answer
1.0K+ views

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 .

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

Thank you.

Marin Bratanov
Telerik team
 answered on 26 Nov 2018
4 answers
297 views

I have a simple form:

@Model MyViewModel

<form method="post" action='@Url.Action("Submit")'>

    <div class="demo-section k-content">

        @Html.TextBoxFor(x => x.SomeRequiredField);

        @(Html.Kendo().Upload() .Name("files") .HtmlAttributes(new { aria_label = "files" }) )

        <p style="padding-top: 1em; text-align: right"><input type="submit" value="Submit" class="k-button k-primary" /></p>

    </div>

</form>

 

public ActionResult Submit(MyViewModel vm, IEnumerable<HttpPostedFileBase> files){

    if(ModelState.Valid) {

        ... do stuff

    } else {

        return View(vm);

    }

}

 

If I select a bunch of files in my upload control, and push the Submit button, suppose validation failed and the view is posted back, however my selected files are lost and I have to reselect them.

How do I restore the previously selected files in the file upload control (synchronous mode) when the form fails validation and is posted back?

 

Nencho
Telerik team
 answered on 15 Oct 2018
1 answer
45 views

Hi,

 

When I upload a file using the Upload control, I want to be able to change the name of the file on the server, but I want the user to see the original file name.

 

Is there a way to have a different name and value for each file in the list? If so, how is the value set?

 

Thanks,

Jess

Ivan Danchev
Telerik team
 answered on 11 Oct 2018
2 answers
690 views

I try to use drag and drop/select from file folder to upload multiple files.  It does not act the way as your demo does.  It can not select multiple files.  It can not drag and drop.  The drag and drop region does not show.   

Here is the code in the Upload.cshtml page:

@using (Html.BeginForm(null, null, FormMethod.Post, new { enctype = "multipart/form-data", id = "form" }))
{
 <div class="form-input">
  <div>
   The Upload can be used as a drop-in replacement
   for file input elements.
  </div>
  <div>
   @(Html.Kendo().Upload()
   .Name("attchments")
   .Async(a => a
    .Save("Upload", "Home")
    .Remove("RemoveUpload", "Home")
    .AutoUpload(true))                
   ))
  </div>
  <p style="padding-top: 1em; text-align: right">
   <button type="submit" class="k-button k-primary">Submit</button>
  </p>
 </div>
}

In _Layout.cshtml page, I have the following links:

<link href="https://kendo.cdn.telerik.com/2018.1.221/styles/kendo.common.min.css" rel="stylesheet" type="text/css" />
<link href="https://kendo.cdn.telerik.com/2018.1.221/styles/kendo.mobile.all.min.css" rel="stylesheet" type="text/css" />
<link href="https://kendo.cdn.telerik.com/2018.1.221/styles/kendo.dataviz.min.css" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/kendo/2018.1.221/kendo.default.min.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/kendo/2018.1.221/kendo.common.min.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/kendo/2018.1.221/kendo.default.mobile.min.css")" rel="stylesheet" type="text/css" />
<link href="https://kendo.cdn.telerik.com/2018.1.221/styles/kendo.dataviz.default.min.css" rel="stylesheet" type="text/css" />
<script src="https://kendo.cdn.telerik.com/2018.1.221/js/jquery.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2018.1.221/js/kendo.all.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2018.1.221/js/kendo.aspnetmvc.min.js"></script>
<script src="@Url.Content("~/Scripts/kendo/2018.1.221/jszip.min.js")"></script>
<script src="@Url.Content("~/Scripts/kendo.modernizr.custom.js")"></script>

 

What do I missed?  

Thanks in advance for your help!

Anieda

 

Anieda Hom
Top achievements
Rank 1
 answered on 11 Sep 2018
2 answers
1.2K+ views

I've been searching and and I cannot find a thread or answer for what I'm doing specifically. I have a site where a user will be creating a record called 'ManualProcess'. In the pop-up they will enter general information about the record and then with the Upload() select files to be uploaded and associated to this main record. The files will be stored in a separate table name 'ManualPrcoessDeocuments' with a FK relationship back to the 'ManualProcess' record.

 

What I'm trying to do is have the HttpPostedFileBase[] object be passed back to the controller along with the 'ManualProcess' record. I have been able to get it to call and pass a value using the async option but that occurs before they have sent the main record data. So ido not have the main record id to associate the documents with. 

Below is the grid code.

@(Html.Kendo().Grid(Model).Name("ManualWorkflowProcess").Columns(c =>
      {
          c.Bound(e => e.Name);
          c.Bound(e => e.Description);
          c.Bound(e => e.ApprovalProcessName);
          c.Bound(e => e.Active).ClientTemplate("<input type='checkbox' disabled='disabled' value='#= Active #' " + "# if (Active) { #" + "checked='Active'" + "# } #" + "/>").Width(100);
          c.Command(command =>
          {
              command.Edit();
              command.Destroy();
          }).Width(200);
      })
          .ToolBar(toolbar => toolbar.Create().Text("Create New Process"))
          .Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("ManualProcessPopUp").Window(w => w.Width(700)))
          .Pageable(pager => pager.AlwaysVisible(false).PageSizes(new List<object> { 5, 10, 20, 100 }))
          .Sortable()
          .Filterable()
          .Groupable()
          .Events(events => events.Edit("Edit"))
          .DataSource(dataSource => dataSource
                  .Ajax()
                  .PageSize(20)
                  .Model(model => model.Id(p => p.Id))
                  .Create(update => update.Action("EditingPopup_Create", "ManualApprovalProcesses"))
                  .Read(read => read.Action("EditingPopup_Read", "ManualApprovalProcesses"))
                  .Update(update => update.Action("EditingPopup_Update", "ManualApprovalProcesses"))
              .Destroy(update => update.Action("EditingPopup_Destroy", "ManualApprovalProcesses"))
        ))

 

Below is the Upload() code in the pop-up template

<div class="editor-label">
    @Html.Label("Files", htmlAttributes: new { @class = "control-label col-md-10" })
</div>
<div class="editor-field">
    @(Html.Kendo().Upload().Name("FileUploads").HtmlAttributes(new { aria_label = "files" })))
</div>

Below is my controller code.

[AcceptVerbs(HttpVerbs.Post)]
        public ActionResult EditingPopup_Update([DataSourceRequest] DataSourceRequest request, ManualApprovalProcess manualProcess, HttpPostedFileBase[] fileUploads)
        {
            if (manualProcess != null && ModelState.IsValid)
            {
                this.Update(manualProcess);
            }
 
            return Json(new[] { manualProcess }.ToDataSourceResult(request, ModelState));
        }

 

So I want to have the file data passed back to the controller so I can create the main record and then use that id and loop over the documents and use that new id when creating the document records.

If this possible the way I'm trying to achieve this? I can;t do the async call because I will be missing come data that I need to properly upload and create the document records as well as upload them to the correct location in Azure.

 

 

 

Phillip
Top achievements
Rank 1
 answered on 17 Aug 2018
3 answers
777 views

Hi,

I am using the file upload template to customize the file upload. Currently Async is set to false, so on select event I am displaying the template. But I want to use the in built function which displays the file size. I am using the below template but I don't want to display the file size in bytes. Is there a way I can achieve this? I created a custom function called formatFileSize() but I want to utilize the inbuilt function if available.

 

<script id="uploadFileTemplate" type="text/x-kendo-template">
        <div>
            <span class="k-file-extension-wrapper">
                <span class="k-file-extension">#=files[0].extension#</span>
                <span class="k-file-state"></span>
            </span>
            <span class="k-file-name-size-wrapper">
                <span class="k-file-name" title="#=name#">#=name#</span>
                <span class="k-file-size">#=formatFileSize(size,2)#</span>
            </span>
            <button id='btnFileDelete' type='button' class='k-upload-action' style='position: absolute; right: 0;' title="Delete">
                <span title="Remove" class="k-icon k-i-close k-i-x" aria-label="Remove"></span>
            </button>
        </div>
    </script>

<script type="text/javascript">

        function OnSelectUploadFile(e) {
            setTimeout(function () {
                $('#btnFileDelete > span').addClass('btnFileOverwrite');
                $('#btnFileDelete > span').attr('title', 'Delete the file');
                $('#btnFileDelete > span').text('Delete');
                $('#btnFileDelete').prepend('<i class="fas fa-times"></i>');
            });
            return true;
        }        
        function formatFileSize(bytes,decimalPoint) {
            if(bytes == 0) return '0 KB';
            var k = 1000,
                dm = decimalPoint || 2,
                sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
                i = Math.floor(Math.log(bytes) / Math.log(k));
            return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
        }

    </script>

I am using the below version of Kendo Mvc
2017.3.1018.545

 

 

Sriram
Top achievements
Rank 1
 answered on 07 Jun 2018
1 answer
500 views

When I put a Combobox inside my upload template, it puts a script(Combobox script) within a script (template script).  The browser does not like this and stops rendering correctly.  How do I make this happen?

Thanks

Ivan Danchev
Telerik team
 answered on 09 Apr 2018
Narrow your results
Selected tags
Tags
+? more
Top users last month
Mark
Top achievements
Rank 1
Yurii
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Hon
Top achievements
Rank 1
Iron
Deltaohm
Top achievements
Rank 3
Bronze
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Mark
Top achievements
Rank 1
Yurii
Top achievements
Rank 1
Leland
Top achievements
Rank 2
Iron
Iron
Iron
Hon
Top achievements
Rank 1
Iron
Deltaohm
Top achievements
Rank 3
Bronze
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?