I'm having some issues with Blazor InputFile when using it within a repeating component, specifically getting the OnChange event to call the method in the correct instance of the repeating component.
Here's some code I've put together to demonstrate what I mean (I'm using Radzen components also):
The top level page razor component:
Код: Выделить всё
@page "/testing"
@foreach (var id in testingRepeaterIds)
{
}
@code {
private List testingRepeaterIds = new List { 1, 2, 3 };
}
Код: Выделить всё
TestingRepeater
Код: Выделить всё
@code {
[Parameter] public int ComponentId { get; set; }
private RadzenDataGrid attachmentGrid;
private List attachedFiles = new List();
private async void LinkFilesToComponent(List files, int entityId)
{
if (entityId == ComponentId)
{
foreach (var file in files)
{
attachedFiles.Add(file);
}
attachmentGrid.Reload();
}
}
}
Код: Выделить всё
TestUpload
Код: Выделить всё
Choose File(s)
@code {
[Parameter] public EventCallback OnChange { get; set; }
private List loadedFiles = new();
private bool isLoading;
private string _inputFileId = Guid.NewGuid().ToString();
private async Task LoadFiles(InputFileChangeEventArgs e)
{
isLoading = true;
foreach (var file in e.GetMultipleFiles())
{
var uploadedFile = new AttachmentDto
{
DiskName = Path.Combine("uploads", file.Name),
FileName = file.Name,
FileSize = file.Size,
FileType = file.ContentType,
};
loadedFiles.Add(uploadedFile);
}
await OnChange.InvokeAsync(loadedFiles);
isLoading = false;
}
}
Код: Выделить всё
AttachmentDto
Код: Выделить всё
public class AttachmentDto
{
[MaxLength(1000)]
public string FileName { get; set; }
[MaxLength(1000)]
public string FileType { get; set; }
[MaxLength(1000)]
public long FileSize { get; set; }
[MaxLength(1000)]
public string DiskName { get; set; }
}
Код: Выделить всё
@key
Код: Выделить всё
InputFile
Код: Выделить всё
ComponentId
Код: Выделить всё
TestUpload
Код: Выделить всё
LoadFiles

For context, I'm using .net 8 and Blazor Web App, though my Routes component is set to use InteractiveServerRenderMode(prerender: false) so I think it's essentially like working with Blazor Server.
Источник: https://stackoverflow.com/questions/781 ... gly-unable