Example of Template in ASP.NET MVC FileUpload Control
This ASP.NET MVC File Upload example demonstrates how to customize the file list with template. Browse or select the files to view the file list template.
@Html.UiFileUpload("templateFiles", new UiFileUploadOptions { Id = "uploadTemplate", Label = "Select files", Template = "#uploadRow" })
@Html.UiButton(new UiButtonOptions { Id = "clearbtn", Text = "Clear All" })
<style>
.control_wrapper { max-width: 420px; margin: 0 auto; padding: 20px 0; }
.input-drop { padding: 24px; border: 2px dashed var(--ui-border); text-align: center; }
.property-section .property-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; }
</style>
<template id="uploadRow">
<div class="upload-row">
<span class="upload-ext">${extension}</span>
<span class="upload-info">
<span class="upload-name">${name}</span>
<span class="upload-meta"><span class="upload-size">${size}</span> · <span class="upload-status">${status}</span></span>
<span class="upload-progress"><span data-ui-progress></span></span>
</span>
<button type="button" class="upload-remove" data-ui-action="remove" aria-label="Remove ${name}">Remove</button>
</div>
</template>
<div class="control-section"><div class="control_wrapper">
@Html.UiFileUpload("templateFiles", new UiFileUploadOptions { Id = "uploadTemplate", Label = "Select files", Template = "#uploadRow" })
</div></div>
<style>
.upload-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--ui-border); border-left: 4px solid var(--ui-accent); border-radius: 6px; background: var(--ui-surface); }
.upload-ext { min-width: 40px; padding: 4px; border-radius: 4px; background: var(--ui-row-hover-bg); font-size: 11px; font-weight: 600; text-align: center; text-transform: uppercase; }
.upload-info { display: flex; flex: 1; flex-direction: column; min-width: 0; }
.upload-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-meta { color: var(--ui-muted); font-size: 12px; }
.upload-progress { height: 3px; margin-top: 4px; background: var(--ui-row-hover-bg); }
.upload-progress span { display: block; height: 100%; background: var(--ui-accent); }
.upload-remove { border: 0; background: transparent; color: var(--ui-accent); font-size: 12px; cursor: pointer; }
</style>
<div class="demo-property-panel property-section" title="Properties">
<div class="property-row">@Html.UiButton(new UiButtonOptions { Id = "clearbtn", Text = "Clear All" })</div>
</div>
<script>
// Syncfusion: Clear All empties the list of the file upload
document.getElementById('clearbtn').addEventListener('click', function () { window.Lumen.get('uploadTemplate').clear(); });
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class UploaderController : Controller
{
// The page is Views/Uploader/Template.cshtml; it draws what ViewData holds.
public ActionResult Template()
{
return View();
}
}
}
@* Install once: Install-Package Lumen.UI.Mvc (or: dotnet add package Lumen.UI.Mvc) *@
@* Views/Web.config: <add namespace="Lumen.UI.Mvc" /> *@
@* Views/Shared/_Layout.cshtml *@
<head>
@Html.UiStyles()
<link rel="stylesheet" href="~/Content/site.css" />
</head>
<body>
@RenderBody()
@Html.UiScripts()
@RenderSection("scripts", required: false)
</body>
The Uploader control allows to customize its file list using template property. The template used for each file in file list.
In this example, the backend service used in the saveUrl and removeUrl endpoints for saving and removing files is intended for demonstration purposes only. The uploaded files are subjected to thorough validation, including verification of file names and the application of security checks. Therefore, this service is not recommended for production use, and the configuration of a custom backend save and remove service is advised. Additional implementation details can be found in the saveUrl and removeUrl documentation.