Hi Steve, first, thank you for this great component!
I wrapped InputFile in a reusable component CustomInputFile that supports upload/download/delete functionality by calling methods on a back-end FileController, and notifies the parent component about changes through OnFileUploaded EventCallback.
ProjectDataModel pd = new ProjectDataModel();
...
private async Task SubmitData()
{
System.Console.WriteLine("Window 1: Data submitted.");
}
async Task CreateProjectDataModel()
{
if (pd != null && !string.IsNullOrEmpty(paramProjectCode))
{
await HttpClient.SendJsonAsync(HttpMethod.Put, "api/ProjectsData/Edit", pd);
}
else
{
pd = await HttpClient.SendJsonAsync<ProjectDataModel>(HttpMethod.Post, "api/ProjectsData/Create", pd);
}
UriHelper.NavigateTo("/Dashboard/fetch");
}
void Cancel()
{
UriHelper.NavigateTo("/Dashboard/fetch");
}
public class ProjectDataModel
{
[Required]
[Key]
public string ProjectCode { get; set; }
[Required]
public string ProjectName { get; set; }
public Guid DbcFileId { get; set; }
public string DbcFileName {get; set; }
public Guid ReferenceTermsFileId { get; set; }
public string ReferenceTermsFileName { get; set; }
}
Because ProjectCode and ProjectName properties are specified, when I upload a file (in my case Dbc file), the validation passes and method CreateProjectDataModel gets called before I upload the second file, ReferenceTerms.
My question is, how do I make InputFile not to call CreateProjectDataModel of parent EditForm ? I still want to have validation on the file info(DbcFileId !=Guid.Empty or regex validation on file name).
File presence is not necessary for the EditForm model to be valid. File can be uploaded later, after saving ProjectDataModel.
Hi Steve, first, thank you for this great component!
I wrapped
InputFile
in a reusable componentCustomInputFile
that supports upload/download/delete functionality by calling methods on a back-endFileController
, and notifies the parent component about changes throughOnFileUploaded
EventCallback.When using it in
EditForm
of the parent .razor page, on finished upload, EditForm is also submitted. Here is the code of parent component:Code behind the parent page is very simple
Because
ProjectCode
andProjectName
properties are specified, when I upload a file (in my case Dbc file), the validation passes and methodCreateProjectDataModel
gets called before I upload the second file, ReferenceTerms.My question is, how do I make InputFile not to call CreateProjectDataModel of parent EditForm ? I still want to have validation on the file info(DbcFileId !=Guid.Empty or regex validation on file name).
File presence is not necessary for the EditForm model to be valid. File can be uploaded later, after saving ProjectDataModel.