For each of the fields, we have added a span tag where the error message is displayed in a red color when the validation fails. When the validation succeeds, there will be no error message displayed. The attribute value of asp-validation-for represents the field name for which the validation error message has to be displayed. For example, we have used the span tag with the asp-validation-for attribute and with the Name value, which tells ASP.NET MVC to display the validation error message for the Name field.
Views/Employee/Index.cshtml looks as follows:
Go to https://goo.gl/k9JMRf to access the code.
@model MVCEF.ViewModels.EmployeeAddViewModel
@*
//For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
}
...
<td>
<span asp-validation-for="Name" style="color:red"></span>
</td>
...
Make sure you have Views\_ViewImports.cshtml to enable tag helpers, as follows: @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers