How to add validation message for required controls

40 Views Asked by At

I have an ASP.NET Core MVC form with few controls as required. I have added required attribute in th element. It is not going to next page if there is no data for the control but I am unable to add validation message "Please provide data for required field".

How can I add that?

<div class="col-xs-12">
     @Html.TextAreaFor(m => Model.StudentName, new { @class = "form-control", required = "required" })
</div>

UI

enter image description here

1

There are 1 best solutions below

0
Ronnie Royston On

HTML does it like this.

<form>
  <label for="choose">Write something</label>
  <input type=text required />
  <input type="submit" value="Submit">
</form>