I'm working on an ASP.Net MVC 5 project uisng razor views.
I have multiple textarea fields in a form using html helpers.
Everything seems to be working ok however the labels for textareas don't show the "*" to denote a required field like the other fields do. Is there a special reason for this? How do I get it to do that?
My model looks like this (only relevant info shown):
[Required, DisplayName("Agreed Action")]
public string AgreedActionText { get; set; }
My View looks like this:
<div class="form-group">
@Html.LabelFor(model => model.AgreedActionText, new { @class = "col-xs-12 col-sm-2 col-md-2 control-label" })
<div class="col-xs-12 col-sm-10 col-md-10">
@Html.TextAreaFor(model => model.AgreedActionText, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.AgreedActionText)
</div>
</div>
Working example:
Model:
[Required, DisplayName("Action Title")]
public string ActionShort { get; set; }
View:
<div class="form-group">
@Html.LabelFor(m => m.ActionShort, new { @class = "col-xs-12 col-sm-4 col-md-4 control-label" })
<div class="col-xs-12 col-sm-8 col-md-8">
@Html.TextBoxFor(m => m.ActionShort, new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.ActionShort)
</div>
</div>
This works:
<label class="col-xs-12 col-sm-2 col-md-2 control-label" for="AgreedActionText">Agreed Action Text<span style="color:red"> *</span></label>
But it's not really the solution I was after, I want the helper to automatically know it's a required field and add the asterix like it does with text boxes and other input fields.