When using scaffolding in asp.net core 2.2, is there a way to make properties scaffold as Hidden Inputs?
Unfortunately [HiddenInput(DisplayValue=false)]
does not seem to work...
HiddenInput(DisplayValue=false)
is Ok and causes the property scaffold as hidden.
Note that after scaffolding, it doesn't generate an input of type Hidden in your code, instead when you run the application <input asp-for="HiddenProperty" />
becomes <input type="hidden" />
.
Here is a sample:
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
[HiddenInput(DisplayValue = false)]
public int? Age { get; set; }
}
View:
<form asp-action="Create">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="Name" class="control-label"></label>
<input asp-for="Name" class="form-control" />
<span asp-validation-for="Name" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Age" class="control-label"></label>
<input asp-for="Age" class="form-control" />
<span asp-validation-for="Age" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-primary" />
</div>
</form>