Example of Custom Drop Area in ASP.NET MVC FileUpload Control
This ASP.NET MVC File Upload example demonstrates how to configure custom drop area of the Uploader. You can drop the files into specified custom drop area location to upload.
@Html.UiFileUpload("fileupload", new UiFileUploadOptions { Label = "Browse", Multiple = true, MaxFiles = 5, MaxFileSize = 1048576, DropAreaId = "customDropArea", SaveUrl = Url.Action("Save", "UploadDemo"), RemoveUrl = Url.Action("Remove", "UploadDemo") })
<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>
<div class="control-section">
<div class="control_wrapper">
<div id="customDropArea" class="input-drop">Drop files here to upload</div>
@Html.UiFileUpload("fileupload", new UiFileUploadOptions { Label = "Browse", Multiple = true, MaxFiles = 5, MaxFileSize = 1048576, DropAreaId = "customDropArea", SaveUrl = Url.Action("Save", "UploadDemo"), RemoveUrl = Url.Action("Remove", "UploadDemo") })
</div>
</div>
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/CustomDropArea.cshtml; it draws what ViewData holds.
public ActionResult CustomDropArea()
{
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 set any external element as drop area using the dropArea property.
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.
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.