I have a .NET MVC CORE 5 application and in the Create.cshtml view, I want some of the fields in the form to be hidden so that users cannot set the values.
Suppose the Create.cshtml currently has a field like this:
<div class="form-group"> <label asp-for="Hremail" class="control-label"></label> <input asp-for="Hremail" class="form-control" /> <span asp-validation-for="Hremail" class="text-danger"></span> </div>
The browser page source will be like this:
<div class="form-group"> <label class="control-label" for="Hremail">Hremail</label> <input class="form-control" type="text" id="Hremail" name="Hremail" value="" /> <span class="text-danger field-validation-valid" data-valmsg-for="Hremail" data-valmsg-replace="true"></span> </div>
to set the value myself.
Or maybe I can make the entire div tag surrounding it not be visible, or maybe even display: none.
I do see how to make the field hidden for all views by changing the model with the [HiddenInput] attribute; but I only want it hidden for that one view.
That's according to this:
Another way I can think of is to remove the MVC generated tag helper and replace it with an HTML helper as is done here:
Maybe there is a better way altogether.
Does anyone have any suggestions on this?