Search results

Achieve Invisible Upload in ASP.NET MVC Uploader control

25 Oct 2021 / 1 minute to read

You can achieve the invisible upload feature by using the selected event in uploader control. Refer to the following example.

razor
invisible.cs
Copied to clipboard
<div class="control_wrapper">
    <div id='preview'></div>
      @Html.EJS().Uploader("UploadFiles").AllowedExtensions(".png, .jpg, .jpeg").Selected("onSelect").AsyncSettings(new Syncfusion.EJ2.Inputs.UploaderAsyncSettings { SaveUrl = "https://ej2.syncfusion.com/services/api/uploadbox/Save", RemoveUrl = "https://ej2.syncfusion.com/services/api/uploadbox/Remove" }).Render()
</div>
<script>
    function onSelect(args) {
        for (var i = 0; i < args.filesData.length; i++) {
            var liparentDiv = ej.base.createElement('div', { className: 'image-list' });
            var liImage = ej.base.createElement('img', { className: 'image' });
            liparentDiv.appendChild(liImage);
            readURL(liImage, args.filesData[i]);
            document.getElementById('preview').appendChild(liparentDiv);
        }
        args.cancel = true;
    }

    function readURL(liImage, file) {
        var imgPreview = liImage;
        var imageFile = file.rawFile;
        var reader = new FileReader();
        reader.addEventListener('load', () => {
            imgPreview.src = reader.result;
        }, false);
        if (imageFile) {
            reader.readAsDataURL(imageFile);
        }
    }
</script>
Copied to clipboard
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace EJ2CoreSampleBrowser.Controllers.TextBoxes
{
    public partial class UploaderController : Controller
    {
        public ActionResult DefaultFunctionalities()
        {
            return View();
        }
    }
}

You can also explore ASP.NET MVC File Upload feature tour page for its groundbreaking features. You can also explore our ASP.NET MVC File Upload example to understand how to browse the files which you want to upload to the server.