For some reason the HiddenFor helper in .NET Core (2.1.4) MVC is not setting a value on the hidden input element despite a value being present on the model property it represents.
If I manually create a hidden attribute and use IdFor, NameFor and manually set the value it works as expected.
// This works and has a value attribute with a value
<input type="hidden" id="@Html.IdFor(x => x.Fields[componentIndex].Value)" name="@Html.NameFor(x => x.Fields[componentIndex].Value)" value="@Model.Fields[componentIndex].Value"/>
// This has a value attribute but it's empty
@Html.HiddenFor(x => x.Fields[componentIndex].Value)
Note in both cases the generated names and id's are the same.
If I use a HiddenFor and provide a new { @Value=... }
with the value it also doesn't set.
The only difference between the HiddenFor's that set a value (using the same code but a different component index) is that they are supplied on post and this problematic one is set in the controller.