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.v24.2.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.C#public ActionResult UploadFile(IFormFile myFile) { // ... }
Use the
Name
property value to get the uploaded file from form variables.C#public ActionResult UploadFile() { // ... var myFile = Request.Form.Files["myFile"]; // ... }
The following example implements 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();
}
}