You can add an asterisk to a required field purely through CSS.
First, create a CSS class for it:
.required::after
{
content: "*";
font-weight: bold;
color: red;
}
This will append a red asterisk to any element with the "required" class.
Then, in your view, simply add the new class to your label:
@Html.LabelFor(m => m.Name, new { @class="required" })
Even better might be a custom HTML Helper that discerns if the field has a [Required] attribute, and if so, adds the required
CSS class.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…