ASP.NET MVC: Foolproof Validation not working

6.2k views Asked by At

In this thread I got the advice to use FoolProof to solve my problem. Thats what Im trying to do right now. But yet, I could not find the reason Foolproof is not working in my project. So I will give you the view and how I included Foolproof there, the model and how I added Foolproof as a bundle, so maybe someone of you sees my mistake.

View:

 @section Scripts {
         @Scripts.Render("~/bundles/jqueryval")
         @Scripts.Render("~/bundles/mvcfoolproof")
            }

BundleConfig:

public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                        "~/Scripts/jquery-{version}.js"));

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

            bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
                        "~/Scripts/jquery-ui-{version}.js"));

            bundles.Add(new ScriptBundle("~/bundles/datatables").Include(
                        "~/Scripts/DataTables/jquery.dataTables.js"));

            bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                        "~/Scripts/modernizr-*"));

            bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                      "~/Scripts/bootstrap.js",
                      "~/Scripts/respond.js"));

            bundles.Add(new StyleBundle("~/Content/css").Include(
                      "~/Content/bootstrap.css",
                      "~/Content/site.css",
                      "~/Content/jquery-ui.css",
                      "~/Content/dataTables.css"));

            bundles.Add(new ScriptBundle("~/bundles/mvcfoolproof").Include(
                    "~/Scripts/MicrosoftAjax.js",
                    "~/Scripts/MicrosoftMvcAjax.js",
                    "~/Scripts/MicrosoftMvcValidation.js",
                    "~/Scripts/MvcFoolproofJQueryValidation.min.js",
                    "~/Scripts/MvcFoolproofValidation.min.js",
                    "~/Scripts/mvcfoolproof.unobtrusive.min.js"));

        }

Model:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using Foolproof;

public int CustomerID {get; set;}
public bool ValRequired {get; set;}
[RequiredIfTrue("ValRequired")]
public string NameofCustomer { get; set; }

So, the problem is, if I apply like that the applications runs without errors, but no validation jumps in at this point, so I would be thankful for any kind of help! :)

1

There are 1 answers

2
Franco Dipre On

In the BundleConfig, replace the last bundle you´ve added by

bundles.Add(new ScriptBundle("~/bundles/mvcfoolproof").Include(
            "~/Client Scripts/mvcfoolproof.unobtrusive.js",
            "~/Client Scripts/mvcfoolproof.unobtrusive.min.js",
            "~/Client Scripts/MvcFoolproofJQueryValidation.js",
            "~/Client Scripts/MvcFoolproofJQueryValidation.min.js",
            "~/Client Scripts/MvcFoolproofValidation.js",
            "~/Client Scripts/MvcFoolproofValidation.min.js"));

When you install the Foolproof package the js files are located in Client Scripts folder, not in Scripts folder.