In Core MVC there is anew concept as Tag helpers.
We could previously create custom html helpers to attach some classes based on the validation data annotations such as [Required].
As TagHelpers arq quite new area I cannot find anough resources to achieve the following:
here is the view model:
[Required]
public Gender Gender { get; set; }
view:
<label class="control-label col-md-3 required" asp-for="Gender"></label>
css:
.required:after {
content: "*";
font-weight: bold;
color: red;
}
output:
But I don't want to manully add the required css class in the label. Somehow I shoudl be able to extend the LabelTagHelper to read model data annotations and if it has the [Required] then add required class in the label element.
Thanks,
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…