In my UploadFilesViewModel
I have a property:
[HiddenInput(DisplayValue = false)]
public bool DirBlocked { get; set; }
and in my view, the following markup for it:
@Html.HiddenFor(m => m.DirBlocked)
When I execute the following code in my GET action:
var model = new UploadFilesViewModel { UserBaseDir = await GetUserBaseDirAsync() };
model.DirBlocked = true;
return View(model);
The hidden input for DirBlocked
renders as follows:
<input data-val="true" data-val-required="The DirBlocked field is required." id="DirBlocked" name="DirBlocked" type="hidden" value="True">
Yet when I execute the following code in the POST action:
// Hard 'true' just for debugging.
//if (files.Any() && !HasDirAccess(model.UploadDir))
if (true)
{
model.DirBlocked = true;
return View(model);
}
The same hidden input renders as follows:
<input data-val="true" data-val-required="The DirBlocked field is required." id="DirBlocked" name="DirBlocked" type="hidden" value="False">
That is, it loses the true
value assigned to the DirBlocked
property. What could be causing this? Normally when I do a return View(model)
in a POST action all model properties are rendered correctly, as they are set.