Strange issue in Blazor client when the model changes #22816
              
                Unanswered
              
          
                  
                    
                      carlblanchard
                    
                  
                
                  asked this question in
                General
              
            Replies: 0 comments
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
-
Hi All. I thought I'd raise this as a discussion rather than a bug as it may be something I've created, or perhaps a lack of understanding.,.
In my Blazor client application, I have a select list of countries. I populate from my model (ExistingRecords) with the countries to display in the select.
My Model looks like this
When I select one of the items from the select list to edit. I set the NewOrEditItem to the value selected. This, in turn, causes the select list to rerender. I know it rerenders because I have debug.writes and the first item is always selected rather than the one chosen.
If I remove the setting of NewOrEditItem then the value I selected remains in the dropdown list.
My guess that due to the model being updated, the StateHasChange event is fired and everything gets updated. I've overcome my problem by directly setting the selected value to the item in the NewOrEditItem. My concern is, this is a simple model, overtime as my models become more complicated this will become more problematic.
Should I be breaking my models down i.e. LoadModel, NewOrEditModel etc.
Or is there a way to cause partial updates only when parts of the model change?
Many thanks for reading, look forward to your comments.
Beta Was this translation helpful? Give feedback.
All reactions