Why should I make my Bundle Twice?

In the project, MVCI include the necessary links for validationusing:

@Scripts.Render("~/bundles/jqueryval")

On my page _Layout. But, for example, the Registercheck does not work on my page unless I add this code to the page Register. In both cases, when I look at the source of my page, I see the necessary links there.

<script src="/Scripts/jquery.unobtrusive-ajax.js"></script>
<script src="/Scripts/jquery.validate.js"></script>
<script src="/Scripts/jquery.validate.unobtrusive-custom-for-bootstrap.js"></script>
<script src="/Scripts/jquery.validate.unobtrusive.js"></script>

So everything is working fine. It does not add links twice, but I could not understand what is the difference?

Here is my bundle code:

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

Note. I pass a few style packages in mine _Layoutand does not cause any problems.

+4
source share
1

, .

:

<div id="#formDiv> script

<script>
    $(document).ready(function() {
        $.validator.unobtrusive.addValidation("#formDiv");
    });
</script>

custom.js:

//Validation on partial views
    $(function () {
        $.validator.unobtrusive.addValidation = function(selector) {
            //get the relevant form 
            var form = $(selector);
            // delete validator in case someone called form.validate()
            $(form).removeData("validator");
            $.validator.unobtrusive.parse(form);
        };
    });
0

Source: https://habr.com/ru/post/1523649/


All Articles