I have a View whose model is a List of custom types and I want to POST changes for only a single element of the List (model[i]). This POST itself works, except the value is what was originally in the model and not the updated value from the input
View's Model Declaration
@model List<Translation2>
Translation2's type (F#)
type Translation2 = {
Key: string;
RowKey: string;
Value: string;
English: string;
}
The View with a single entity submit
@model List<Translation2>
<form asp-controller="Home" asp-action="Translate" method="POST" >
<table>
<thead>
<th>
<h2>Key</h2>
</th>
<th>
<h2>English</h2>
</th>
<th>
<h2>Translated</h2>
</th>
</thead>
<tbody>
@for(var i = 0; i < Model.Count(); i++)
{
<tr>
<div>
<td class="key-col">
<p style="font-size:large">@Model[i].Key</p>
@Html.HiddenFor(m => m[i].RowKey)
</td>
<td class="val-col">
<input class="fill-void" type="text" asp-for="@Model[i].English" readonly />
</td>
<td class="val-col">
<input class="fill-void" type="text" asp-for="@Model[i].Value" />
</td>
<td>
<a href="@Url.Action("Translate", "Home", new {RowKey=@Model[i].RowKey, Key=@Model[i].Key, Value=@Model[i].Value })" >Save Translation</a>
</td>
</div>
</tr>
}
</tbody>
</table>
</form>
I have also tried to just POST the entire list per ASP.NET Core 1.0 POST IEnumerable<T> to controller but will get
ArgumentNullException: Value cannot be null.
Parameter name: source
Count
MoveNext in Translate.cshtml
@for(var i = 0; i < Model.Count(); i++)
The View with submitting the entire list
@model List<Translation2>
<form asp-controller="Home" asp-action="Translate" method="POST" >
<table>
<thead>
<th>
<h2>Key</h2>
</th>
<th>
<h2>English</h2>
</th>
<th>
<h2>Translated</h2>
</th>
</thead>
<tbody>
@for(var i = 0; i < Model.Count(); i++)
{
<tr>
<div>
<td class="key-col">
<p style="font-size:large">@Model[i].Key</p>
@Html.HiddenFor(m => m[i].RowKey)
</td>
<td class="val-col">
<input class="fill-void" type="text" asp-for="@Model[i].English" readonly />
</td>
<td class="val-col">
<input class="fill-void" type="text" asp-for="@Model[i].Value" />
</td>
<td>
<button type="submit">Save Translation</button>
</td>
</div>
</tr>
}
</tbody>
</table>
</form>
I would really like to know how to solve both ways, if possible, but a solution for either will do at this point.