Load external scripts in modal being loaded via ajax

2

By default, I have a configuration file of various plugins and actions of my system

A simple example is the use of tooltip:

$(".bn-tooltip").tooltip({
    track: true
});

Datepicker:

$('.bn-datepicker').datepicker({
    autoclose: true,
});

I do this because when I use it anywhere on the system, I just call the class I have set there.

Well, it happens that when I load via ajax my modals, it does not recognize these "configurations" and I have to pass within the modal page the same codes I already have, or put the file config.js in modal ...

Is there any elegant solution to not have to insert all the time you will use the same codes or always insert the script files?

    
asked by anonymous 19.01.2015 / 16:07

1 answer

1

The elegant way is to put a section to Scripts in the Modal Layout:

@RenderSection("scripts", required: false)

So, for each View file other than a Partial , just call Views with the following statement at the end of them: / p>

@section scripts 
{
    <script>
        $(".bn-tooltip").tooltip({
            track: true
        });

        $('.bn-datepicker').datepicker({
            autoclose: true,
        });
    </script>
}
    
19.01.2015 / 20:16