Hello,
related to my previous bug report.
When Add / Edit is clicked in the Grid, it causes a Dialog to open.
The dialog has a Form, and if the model for that form is set through OnParametersSet, the method is called in an infinite loop, and the Dialog never gets shown.
Hello Nadezhda,
Thank you for the clarification!
Hello DRASKO,
I revised the attached application in detail and it looks to me that the behavior is a matter of configuration specifics rather than a bug. Let me provide more details and a suggestion on how to solve it.
The OnParametersSet method in Blazor is called whenever a component's parameters are set or updated. In your case, the infinite loop is likely caused by the following line in the OnParametersSet method:
Model = mapper.Map<AddCameraModel>(EditedCamera);
This line updates the Model property every time OnParametersSet is called. If Model is bound to the UI and any change to Model triggers a re-render, this will cause OnParametersSet to be called again, creating an infinite loop.
To break this loop, you should only update Model if EditedCamera has actually changed. You can achieve this by comparing the current EditedCamera with the previous one and only updating Model if they are different.
Here is an updated version of the OnParametersSet method:
private CameraDTO? _previousEditedCamera;
protected override void OnParametersSet()
{
_onParametersSetCalled++;
Console.WriteLine($"OnParametersSet called {_onParametersSetCalled} times");
if (EditedCamera != null && !EditedCamera.Equals(_previousEditedCamera))
{
Model = mapper.Map<AddCameraModel>(EditedCamera);
_previousEditedCamera = EditedCamera;
}
}
This change ensures that Model is only updated when EditedCamera actually changes, preventing the infinite loop.
Having the above in mind, I am marking the current item as "Declined" since it is not a valid bug report.
===
Additional tip:
You have another ticket with the same configuration where you are setting the model in the OnAfterRender. Currently, it is not clear to me why you are setting the model in a different lifecycle events than in the OnInitialized, so I'd like to share some good practices:
Regards,
Nadezhda Tacheva
Progress Telerik
Enjoyed our products? Share your experience on G2 and receive a $25 Amazon gift card for a limited time!