jqueryasp.netjquery-validateunobtrusive-validation

jquery validation displays no error message


I am trying to use jquery validation, but for some reason no error message shows up, even though I try to follow various examples:

<form action="/" id="paaForm" method="post">
    <input type="text" name="testMe" id="testMe" />

<button id="btnSubmit" type="button" value="Save" class="btn btn-default" />

jquery:

$(function () {
   $("#paaForm").validate({
    rules: {
        testMe: {
            required: true
        },
  ...
    $('#btnSubmit').on('click', submit);
  ...

function submit() {
    if (!$("#paaForm").valid()) {
        return;
    }
    ...

EDITED:

I have to add more information. My application is an MVC application, so it uses bundling like this:

bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
            "~/Scripts/jquery.validate*"));

This way, MVC validation based on model attributes works perfectly. But I need more complex validation, that is why I added simple jquery validation. And it doesn't work, as I mentioned above. But if I replace bundling with this one,

           bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                    "~/Scripts/jquery.validate.js"));

jquery validation works, but MVC validation doesn't work, because I exclude "~/Scripts/jquery.validate.unobtrusive.js". Is it possible to make both work?


Solution

  • FYI - if you're using the Unobtrusive Validation plugin, then it constructs the .validate() method automatically. You cannot simply provide your own instance of .validate() as it will be ignored. The plugin is only designed to handle .validate() ONE time on any particular form and all subsequent instances are always ignored.