Hello Team,
Am trying to apply a textfield validation in my code but is not working, please assist. thanks
C#
@Html.TextBoxFor(model => model.FinalPay, new { @class = "form-control", @name = "finalsalary", @id = "finalsalary", @placeholder = "Enter Final Pay" })
@Html.ValidationMessageFor(model => model.FinalPay, "", new { @class = "text-danger" })MODEL CLASS
C#
[Display(Name = "FinalPay")]
[Required(ErrorMessage = "Final pay is required.")]
Vishal JoshiRank #377 · 6.7K reputationPosted Nov 5, 2023, 1:13 AM EST
Hello Emmanuel,
You need to call Jquey for validation before submitting the form if you are using ajax call. please try the below code.
if (!$("#formId").valid()) { return; }Also, make sure you have added the jQuery validation reference properly in the header part of the page or globally. check the below references.
Thank you
Vishal Joshi
Jignesh KumarRank #91 · 22.9K reputationPosted Nov 5, 2023, 1:11 AM EDT
Hello emmanuel,
If you want enalbe client side data annotation in mvc application then you need to refer below list of jquery to your page,
Emmmanuel FIADUFERank #947 · 2.2K reputationPosted Nov 5, 2023, 6:00 AM EST
Thank you Team and Vishal for your support, it is working now as Vishal said
Emmmanuel FIADUFERank #947 · 2.2K reputationPosted Nov 5, 2023, 6:03 AM EST
Thank you Vishal and Kumar it is working now
Vishal YelveRank #178 · 13.6K reputationPosted Nov 4, 2023, 7:43 AM EDT
Hi
Try to add below JQuery on ur page.
Emmmanuel FIADUFERank #947 · 2.2K reputationPosted Nov 4, 2023, 5:39 PM EDT
Hello Vishal, it's not working
Rupesh KahaneRank #136 · 16.4K reputationPosted Nov 4, 2023, 11:21 PM EDT
Refer below article
https://www.c-sharpcorner.com/UploadFile/a8024d/validation-using-data-annotations-in-Asp-Net-mvc-5/