Skip to main content
A newer version of this page is available. .

DxUpload.Name Property

Specifies a unique identifier used to associate the Upload component with uploaded files on the server.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v22.1.dll

NuGet Package: DevExpress.Blazor

Declaration

[Parameter]
public string Name { get; set; }

Property Value

Type Description
String

A string value that specifies the identifier.

Remarks

Specify the Name property to associate the Upload component with the server. This property is used to access uploaded files on the server. You should also set the UploadUrl property to the path of a server-side controller’s action that processes upload requests.

<DxUpload Name="myFile" 
          UploadUrl="https://localhost:10000/api/Upload/Upload/">
</DxUpload>

On the server side, create a controller with an action that accepts the uploaded file, checks it, and saves it to the target location.

Do one of the following to access the uploaded file:

  • Create an action with a parameter whose name matches the Name property value.

    public ActionResult UploadFile(IFormFile myFile) {
        // ...
    }
    
  • Use the Name property value to get the uploaded file from form variables.

    public ActionResult UploadFile() {
        // ...
        var myFile = Request.Form.Files["myFile"];
        // ...
    }
    

The following example demonstrates how to implement the upload controller:

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace BlazorDemo.AspNetCoreHost;
[Route("api/[controller]")]
[ApiController]
public class UploadController : ControllerBase {
    [HttpPost("[action]")]
    public ActionResult Upload(IFormFile myFile) {
        try {
            // Write code that saves the 'myFile' file.
            // Don't rely on or trust the FileName property without validation.
        } catch {
            return BadRequest();
        }
        return Ok();
    }
}

Run Demo: Upload - Overview

See Also