Blog Detail

JQuery validation in MVC6(Asp.Net Core)

30 Jul 16
No Comments
I am new to MVC6(Asp.Net Core) and JQuery stack. I have started my new project in MVC6 and JQuery, with out hands on work experience in MVC. One of the major problems I faced during initial phase of the development was form validation using JQuery. Here I am trying to describe the work around to add validation logic to your form using JQuery validation  and data annotations in MVC.

Step1: Add required data annotations to your model class

Step2: Refer jquery.validate.js and jquery.validate.unobtrusive.js in the view or Layout page. If you don’t have these scripts in your solution, you can get it through NuGet package.

Step 3: $(“#myForm”).valid() will do the magic for you. See the code below.

$("#submitbtn").click(function () {
var form = $("#myForm");
var isValid = form.valid();

if (isValid) { //If there is no validation error
('form is valid');
else {
('form is not valid');

Please Note:
I have made this post in a hurry, if some one need any clarity, feel free to comment.

Leave A Comment