Back to Devexpress

FileUploadErrorEventArgs Class

blazor-devexpress-dot-blazor-5a53e831.md

latest2.8 KB
Original Source

FileUploadErrorEventArgs Class

Provides data for the FileUploadError event.

Namespace : DevExpress.Blazor

Assembly : DevExpress.Blazor.v25.2.dll

NuGet Package : DevExpress.Blazor

Declaration

csharp
public class FileUploadErrorEventArgs :
    FileUploadEventArgs

FileUploadErrorEventArgs is the data class for the following events:

Remarks

This class includes the following properties:

  • FileInfo - Returns information about a file (the name, size, type, etc.)
  • RequestInfo - Returns information about a request’s response (the status and entire message).

The following snippet handles the FileUploadError event and shows a custom error message that is passed from the server.

razor
<DxUpload Name="myFile" UploadUrl="https://localhost:10000/api/Upload/UploadFile/"
          FileUploadError="@OnUploadError">
</DxUpload>
<div class="alert alert-danger @(ErrorVisible? " visible" : " invisible")">@MyError</div>

@code {
    bool ErrorVisible { get; set; } = false;
    string MyError { get; set; }

    void OnUploadError(FileUploadErrorEventArgs e) {
        MyError = e.RequestInfo.ResponseText;
        ErrorVisible = true;
        InvokeAsync(StateHasChanged);
    }
}
csharp
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

[Route("api/[controller]")]
public class UploadController : ControllerBase {
    private readonly IWebHostEnvironment _hostingEnvironment;

    public UploadController(IWebHostEnvironment hostingEnvironment) {
        _hostingEnvironment = hostingEnvironment;
    }

    [HttpPost]
    [Route("UploadFile")]
    public ActionResult UploadFile(IFormFile myFile) {
        // Check whether the file can be uploaded.
         // ...
         return BadRequest("An error occured during file upload.");
    }
}

Inheritance

Object EventArgs FileUploadEventArgs FileUploadErrorEventArgs

See Also

FileUploadErrorEventArgs Members

DevExpress.Blazor Namespace