Asp.net mvc4 clientside check not working

I have client validation in my config and I also include the relevant jquery files to validate, but every time I post the page is sent to the server without first validating the clients. I've pasted in the markup generated in the source below. It seems that the data validity message is reliably generated. Just don't run the check somehow.

I am using the BeginCollection library which is available in Nuget to create my dynamic form. Could this be the reason for my customer verification not working anyway?

    <input class="text-box single-line valid" data-val="true" 
data-val-number="The field DaysAbsent must be a number." 
data-val-required="The DaysAbsent field is required." 
id="students_471abdc8-b190-42da-9f72-ed30a1e33b10__DaysAbsent" 
name="students[471abdc8-b190-42da-9f72-ed30a1e33b10].DaysAbsent" 
type="text" value="0">

      


My web.config:

<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />

      


_Layout.cshtml:

    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/jqueryui")
    @Scripts.Render("~/bundles/jqueryval")
    @RenderSection("scripts", required: false)

      


BundleConfig.cs:

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

      

+3


source to share


1 answer


You mentioned a dynamic form, so if you load your inputs dynamically jquery.validate doesn't know they are. You must "update" your form validations to confirm your new entries.

After adding new input, use this code to "update" the validations for your form:



$('form').removeData('validator');
$('form').removeData('unobtrusiveValidation');
$.validator.unobtrusive.parse($('form'));

      

0


source