Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

img onerror event does not change property on view model

I’m trying to set a flag when the the image fails to load in blazor but it seems that the flag is never updated. What am I doing wrong ?

The fiddle looks like this:


<h1>Hello, world!</h1>

Welcome to your new app.

<img src="https://images.dog.ceo/breeds/dane-great/n02109047_8090" onerror="this.onerror=null; @(() => SetImageFailedFlag())">

<p>Image failed to load @ImageFailedFlag</p>

@code {
    private bool ImageFailedFlag  {get;set;} = false;

    private void SetImageFailedFlag() {
        ImageFailedFlag = true;
        StateHasChanged();
    }
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

To trigger the image load error event in blazor, it should be

<img src="xxx" @onerror="SetImageFailedFlag">
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading