I am building a (static) website in Blazor.wasm where the users upload some number of files. My intention is then (after all the files have passed some basic checks) to iteratively present a set of fields which the users are asked to complete. Only after they have submitted all the [Required]
information and press submit will the next form show up.
I have included a minimal example below.
if (valid_files == numFiles)
{
for (int counter = 0; counter < num_files; counter++)
{
paramList.Add(new ParamsForm { });
<EditForm Model="@paramList[counter]" OnValidSubmit="@SingleSubmit">
<DataAnnotationsValidator />
<ValidationSummary />
<p>
Camera type <br>
<InputText id="cameratype" @bind-Value="@paramList[counter].CameraType" />
</p>
<button type="submit">Submit</button>
</EditForm>
}
<button @onclick="HandleValidSubmit">Upload Data </button>
}
The expected behaviour is that on each iteration, a frech instance of the onbject ParamsForm
is added to the list. We then create a form based of that instance and wait for the user to complete the form. Once they press the Submit
button the next stage of the for
loop begins. Once all the data have been submitted and the for
loop is completed, the Upload data
button should appear and the users are invited to submit all their data to the server.
Instead, none of the code inside the EditForm ...
section is being completed. I.e. - I see no popping up of text boxes, and any code that I put in there (for example @Console.WriteLine("This should show up)
does not seem to be executed. The Upload data
button does not appear and instead an error is thrown complaining that the index is out of range
, which is weird because after the code at the top of the for loop there are no longer any elements being accessed by an index.
I am quite new to interacting between c# and HTML, so I think I can appreciate why what I have shouldn't work, but I don't know how I can go about writing something that will work.
Any advice would be gratefully recieved.