New to Telerik UI for ASP.NET MVC? Start a free 30-day trial
Display File Location for Each Uploaded File
Environment
Product | Telerik UI for ASP.NET MVC Upload |
Progress Telerik UI for ASP.NET MVC version | Created with the 2023.3.1114 version |
Description
How can I display the location of the uploaded file as a link within the Upload component?
Solution
- Define an Upload component in asynchronous mode.
- Use the
TemplateId
option to define a template for rendering the files in the file list. - Update the
Save
Action method to return the file location of the uploaded file. - Subscribe to the
Success
event to intercept the received file location from the server. Select the anchor tag within the file template with jQuery and update thehref
attribute with the respective file location.
View_HtmlHelper
@(Html.Kendo().Upload()
.Name("files")
.TemplateId("fileTemplate")
.Async(a => a
.Save("Async_Save", "Home")
.Remove("Remove", "Home")
.AutoUpload(true)
)
.Events(ev => ev.Success("onSuccess"))
)
<script id="fileTemplate" type="text/x-kendo-template">
<span class="k-progress"></span>
<span class="k-file-group-wrapper">
<span class="k-file-group k-icon k-i-file-image"></span>
<span class="k-file-state"></span>
</span>
<span class="k-file-name-size-wrapper">
<span class="k-file-name"><a href="" target="_blank">#=data.name#</a></span>
</span>
<strong class="k-upload-status">
<button type="button" class="k-button k-icon-button k-button-md k-rounded-md k-button-flat k-button-flat-base k-upload-action"><span class="k-button-icon k-icon k-i-close k-i-x" title="Remove"></span>
</button>
</strong>
</script>