0

@page "/counter"

Counter

Current count: @currentCount

<button class="btn btn-primary" @onclick="IncrementCount">Click me

@code { private int currentCount = 0;

private void IncrementCount() { currentCount++; if (currentCount % 2 == 0) { <img src="~/Images/black_atlasian_mode copy.png" /> } else { <img src="~/Images/teal_atlasian_mode copy.png" /> } } 

}

1 Answer 1

0

You are close. Image hase to be in html part, you are changing src only:

Current count: @currentCount <button class="btn btn-primary" @onclick="IncrementCount">Click me </button> <img src="@src" /> @code { private int currentCount = 0; string src = "~/Images/black_atlasian_mode copy.png"; private void IncrementCount() { currentCount++; if (currentCount % 2 == 0) { src = "~/Images/black_atlasian_mode copy.png"; } else { src = "~/Images/teal_atlasian_mode copy.png"; } } } 
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks I was able to take your code and make it work. @page "/counter" to the top. I wasn't able to get the images to work until I put them directly into the wwwroot. I was think that if I added a Folder called Images under the wwwroot and place them there it would. Any suggestions?
Yes, images has to me somewhere inside the wwwroot. The rest of the code is not accessible. If you add additional folder it will make your path as this: src="images/image.png". If you have a lot of images and you don't want to drag them everywhere, use something like Blob Storage and track the urls in db..

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.