1,674 questions
Hi @MIPAKTEH_1,
To add titles to each picture in your Blazor page, you can modify the for loop to include titles for each image.
More details, you could refer to below codes:
@page "/House"
@inject NavigationManager Navigation
<h1>HOUSE</h1>
@for (int i = 0; i < images.Count; ++i)
{
<div style="display:inline-block; text-align:center; margin:10px;">
<img src=@($"/Images/{images[i]}")
style="width:200px; cursor:pointer"
@onclick="() => NavigateToNewPage(i)" />
<div>@titles[i]</div>
</div>
@if ((i + 1) % 3 == 0)
{
<br />
}
}
@code {
// Define the list of image file names
private readonly List<string> images = new()
{
"H_1.png",
"H_2.png",
"H_3.png",
"H_4.png"
};
// Define the list of titles corresponding to the images
private readonly List<string> titles = new()
{
"Title 1", "Title 2", "Title 3", "Title 4"
};
// Method to navigate to the new page
private void NavigateToNewPage(int imageIndex)
{
Navigation.NavigateTo("/Counter");
}
}
Result: