@page "/"
@using System.ComponentModel.DataAnnotations;
<h3>FIleUploadTestPage</h3>
<EditForm Model="_myModel" OnSubmit="HandleSubmit">
<DataAnnotationsValidator/>
<ValidationSummary />
<div class="form-group">
<FileUploadComponent @bind-Value="_myModel.File" AllowedTypes="@(new(){".png"})" Label="File"/>
<ValidationMessage For="()=>_myModel.File" />
</div>
<button type="submit">Submit</button>
</EditForm>
@if(_success is not null)
{
@if (_success.Value)
{
<h3>Success</h3>
}
else
{
<h3>Failed</h3>
}
}
@code {
FileModel _myModel = new();
bool? _success = null;
public class FileModel
{
public IBrowserFile? File { get; set; }
public IReadOnlyList<IBrowserFile>? Files { get; set; }
}
void HandleSubmit(EditContext context)
{
if (context.Validate())
{
SuccessAction();
}
else
{
UnSuccessAction();
}
}
void SuccessAction() =>_success = true;
void UnSuccessAction() => _success = false;
}