I'm developing an ASP.NET MVC 5 application with Razor, C# and .NET Framework 4.7.
I have this code on my View:
@for (int index = 0; index < Model.LevelsGtin.Count; index++)
{
<tr>
<td>@Html.TextBoxFor(m => m.LevelsGtin[index].Level, new { @disabled = "disabled" })</td>
<td>@Html.TextBoxFor(m => m.LevelsGtin[index].Gtin )</td>
</tr>
}
If I want to let user to add more elements into Model.LevelsGtin
.
I've been using JavaScript to clone that <tr> ... </tr>
, but the code is very messy, and I think that maybe there is a better way to do it (at least an easier one).
Is there anyway to do it with C# code?
I don't know if there is something in the ASP.NET MVC framework that let add more elements into an array: like a magical add button that adds an element into the Model.LevelsGtin
.