Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

List Model binding in Blazor [duplicate]

$
0
0

For the simplicity, I'm going to keep the code as minimum as possible to describe the issue.

Here is my ViewModel, CompanyImageViewModel class

    public class CompanyImageViewModel    {        public int Id { get; set; }        public string CompanyHash { get; set; }        public string PoseId { get; set; }        public string TankCode { get; set; }        public string Site { get; set; }        public string TitleTag { get; set; }        public string AltTag { get; set; }        public string CaptionTag { get; set; }        public string Filename { get; set; }        public IFormFile ImageFile { get; set; }    }

I want to show multiple such viewmodel in a single page.

@model List<CompanyImageViewModel><div class="container"><h1>Company Image Manager</h1><div class="mb-1"><a asp-action="Index">⬅️Back to Company List</a></div><form method="post">        @for (int i = 0; i < Model.Count; i++)        {           var selectedImageFile = Model.Skip(i).Take(1).FirstOrDefault();<div class="image shadow-sm p-3 mb-5 bg-white rounded d-flex"><div class="imagecontainer"><img id="displayedImage" src="@imageRoot\@selectedImageFile.Filename" alt="Click to change image" style="width: 300px; cursor: pointer;">                    @Html.TextBoxFor(r => r[i].ImageFile, new {@class="imageUpload"});<input type="file" asp-for="@selectedImageFile.ImageFile" class="imageUpload" accept="image/*" style="display: none;"></div><div class="inputFields"><div class="title"><div class="mb-3"><label asp-for="@selectedImageFile.TitleTag" class="form-label">Image Title</label><input class="form-control" asp-for="@selectedImageFile.TitleTag"></div></div></div></div>        }<button type="submit" class="btn btn-primary">Save</button></form><div class="error-log" id="error-log"></div></div>

I am looking for best way to bind models with html elements in this situation.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>