I have a field that is hidden in the ui under some conditions. When that field is hidden and not displayed in the UI, it gets updated to default values when the form is submitted.
@if (canManageAllEmployees)
{
<label title="Selecting this option will hide the employee's pay rate on all Profit Center pages." asp-for="PortalEmployee.HidePayRateIndicator" class="active"></label>
<input asp-for="PortalEmployee.HidePayRateIndicator" />
}
else
{
Model.PortalEmployee.HidePayRateIndicator = (bool)ViewBag.HidePayRate;
<p> @Html.Raw(Model.PortalEmployee.HidePayRateIndicator)</p>
}
I have tried to set the Model value, but still the value is being false in the backend, though it is actually true.
I have one option for this, that is to set that field Hidden, but it will be still visible in the UI (through Inspecting tools in browser), and can still be updated.
So what could be an alternative for HiddenFor, or preserve the value without being able to update in any way from the browser or UI.