I am trying to develop an app in which a quiz is generated dynamically at various instances to track a patient's progress. I am able to generate various instances of the form, have the form filled out and save the results. The problem is that the answers to the quiz are not posted upon submit - just the default values.
Generated Form
Co-Pilot tells me that user input is likely being lost due to the reinitialization of the TestFormModel
. However, I am guarding against that, I thought.
OnInitializedAsync()
Here's the submit code: Submit Code
Any help in figuring this out greatly appreciated. The code for this is located at .
I am trying to develop an app in which a quiz is generated dynamically at various instances to track a patient's progress. I am able to generate various instances of the form, have the form filled out and save the results. The problem is that the answers to the quiz are not posted upon submit - just the default values.
Generated Form
Co-Pilot tells me that user input is likely being lost due to the reinitialization of the TestFormModel
. However, I am guarding against that, I thought.
OnInitializedAsync()
Here's the submit code: Submit Code
Any help in figuring this out greatly appreciated. The code for this is located at https://github.com/rswetnam/SequentialTests.
Share Improve this question asked Feb 5 at 13:08 RBSRBS 35 bronze badges 2 |1 Answer
Reset to default 0Blazor generally support foreach
for list render. But when using for
, blazor may not correctly track changes because the index variable (i) changes during rendering. You could try create new variable inside the loop, such as following:
@for (int i = 0; i < 6; i++)
{
int index=i;
//use the "index" instead of i
var question = @TestFormModel.Questions[index];
...
(@bind-Value=MyDictionary[i])
this is equivalent to @(e => MyDictionary[i] = e) but i will always be equal to the last loop. Check this: shauncurtis.github.io/Building-Blazor-Applications/… – Bisjob Commented Feb 5 at 16:52