Question

I'm Use kendo ui file Upload in mvc project. delete a file not confirmation and i want a confirm before delete

@(Html.Kendo().Upload()
                .Name("attachments")
                .TemplateId("fileTemplate")
                .Async(async => async.Save("SaveFile", "Upload", new { folderType = ViewBag.FolderType, recordid = ViewBag.TableXRef })
                .Remove("RemoveFile", "Upload")
                .AutoUpload(true))
                .Files(files =>
                {
                    foreach (var f in Model.OrderByDescending(f => f.ModifyDate))
                    {
                        files.Add().Name(f.FileName.ToString())
                            .Extension(f.Extension).Size(f.Size);
                    }
                })
              )

 <script id="fileTemplate" type="text/x-kendo-template">
    <div>
        <span class="k-filename">"#=name#"</span>
        <p> <a href='javascript:downloadAttachments("#=name#")' >#=name#</a> </p>
        <button id='btnDelete' type='button' class='k-upload-action' style='position: absolute; top: 0; right: 0;'>
        </button>
    </div>
    </script>
Was it helpful?

Solution

You should use the remove event of the Upload widget and cancel it if the confirmation fails.

function onDelete(e){
     if(!confirm("Are you sure you want to remove the item?")){
           e.preventDefault();
      }
}

OTHER TIPS

Shouldn't be any different than regular javascript. Add an onclick to the button.

<button id='btnDelete' type='button' class='k-upload-action' 
style='position: absolute; top: 0; right: 0;' onclick='return confirm("Are you sure?");'>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top