I am trying a register with popup window and ı am using Html.ValidationMessageFor but when I try to register under textboxfor there is nothing showing. can you help me ?
these are my code
I am trying a register with popup window and ı am using Html.ValidationMessageFor but when I try to register under textboxfor there is nothing showing. can you help me ?
these are my code
You can use jQuery Validation in order to validate form fields as shown below:
Step 1: Add the necessary DataAnnotations
to the related Model
properties as shown below:
[Required(ErrorMessage = "Required field")]
[MaxLength(50)]
[Display(Name = "Lab")]
public string Name { get; set; }
Step 2: Add the necessary script files to the _Layout
or View
page:
<script src="/Scripts/jquery.validate.js"></script>
<script src="/Scripts/jquery.validate.unobtrusive.js"></script>
Step 3: Use the ValidationMessageFor
annotation as shown below. Note that you can use some properties i.e. maxlength, etc. also:
@Html.TextBoxFor(m => m.Name, new { maxlength = "50", @class = "form-control" })
@Html.ValidationMessageFor(m => m.Name, null, new { @class = "field-validation-error" })