Back to Devexpress

DxUpload.FileUploadError Event

blazor-devexpress-dot-blazor-dot-dxupload-ad692c2e.md

latest2.8 KB
Original Source

DxUpload.FileUploadError Event

Fires if an error occurs during file upload.

Namespace : DevExpress.Blazor

Assembly : DevExpress.Blazor.v25.2.dll

NuGet Package : DevExpress.Blazor

Declaration

csharp
[Parameter]
public EventCallback<FileUploadErrorEventArgs> FileUploadError { get; set; }

Event Data

The FileUploadError event's data class is FileUploadErrorEventArgs. The following properties provide information specific to this event:

PropertyDescription
FileInfoReturns information about a file. Inherited from FileUploadEventArgs.
RequestInfoReturns information about a request’s response.

Remarks

The FileUploadError event occurs if a file was not uploaded to the server because of an error. If a file was uploaded successfully, the FileUploaded event occurs.

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.");
    }
}

See Also

DxUpload Class

DxUpload Members

DevExpress.Blazor Namespace