In this official ASP.NET Core tutorial, I can use an Input Tag Helper as shown below. But due to a known model binding issue of form elements in a foreach loop, I want to use for loop
instead. Question: If I were to replace @foreach (var item in Model)
with @for (int i=0; i < Model.Count(); i++)
in the following View
. What would be my asp-for
in <input asp-for="???" />
? For some reason, intellisense is not recognizing, e.g, Model[i].BlogId or @Model[i].BlogId
@model IEnumerable<EFGetStarted.AspNetCore.NewDb.Models.Blog>
@{
ViewBag.Title = "Blogs";
}
<h2>Blogs</h2>
<p>
<a asp-controller="Blogs" asp-action="Create">Create New</a>
</p>
<table class="table">
<tr>
<th>Id</th>
<th>Url</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
<input asp-for="@item.BlogId" />
</td>
<td>
<input asp-for="@item.Url" />
</td>
</tr>
}
</table>
for loop
because of the problem with foreach loop (as described here). Also, @model need to be IEnumerable. – Freshenfor
loop withIEnumerable<T>
- it would need to beIList<T>
– Perpendicular