Hi @MIPAKTEH_1,
If each uploading logic implements are quite different and the image count is known. You could just define them manually:
@for (int i = 0; i < images.Count; ++i)
{
string tempImageName = images[i].Page;
string tempTitle = images[i].Title;
<div style="display:inline-block; text-align:center; margin:10px;">
<img src=@($"/Images/{images[i].Image}")
style="width:200px; cursor:pointer"
@onclick="() => NavigateToNewPage(tempImageName)" />
<div>@tempTitle</div>
@if (i == 0)
{
<InputFile OnChange="UploadedFile1" />
}
else if (i==1)
{
<InputFile OnChange="UploadedFile2" />
}
else
{
<InputFile OnChange="UploadedFile3" />
}
</div>
@if ((i + 1) % 3 == 0)
{
<br />
}
}
@code {
public class MyViewModel
{
public string Image { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public string Page { get; set; } = string.Empty;
}
private async void UploadedFile1(InputFileChangeEventArgs e)
{
}
private async void UploadedFile2(InputFileChangeEventArgs e)
{
}
private async void UploadedFile3(InputFileChangeEventArgs e)
{
}
}
If your upload implements are similar, and you just want to get each model to do different operation, you could change like below:
@for (int i = 0; i < images.Count; ++i)
{
string tempImageName = images[i].Page;
string tempTitle = images[i].Title;
var image = images[i]; //must add this outside the lamda
<div style="display:inline-block; text-align:center; margin:10px;">
<img src=@($"/Images/{images[i].Image}")
style="width:200px; cursor:pointer"
@onclick="() => NavigateToNewPage(tempImageName)" />
<div>@tempTitle</div>
<InputFile OnChange="@(e => HandleFileSelected(image, e))" />
</div>
@if ((i + 1) % 3 == 0)
{
<br />
}
}
@code {
public class MyViewModel
{
public string Image { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public string Page { get; set; } = string.Empty;
}
//...
private string selectedFileName = "'";
private async void HandleFileSelected(MyViewModel image, InputFileChangeEventArgs e)
{
//...
}
}
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Rena