asp.net mvc - JavaScript/jQuery doesn't work on Editor/Display templates loaded with Ajax -


i created editor , display templates entire object downline.

now 1 of inner objects' text boxes should date-picker.

the thing it's loaded after initial loading using ajax, , included scripts don't work.

i tried include following script on bottom of template, script renders nothing:

@styles.render("~/content/themes/base/css") @scripts.render("~/bundles/jquerytimepicker")  <script type="text/javascript">   alert('dddddddddddddddddddddddddd');   $('.time-picker').timepicker(); </script> 

in code abve added dummy alert prove script isn't running, makes question simpler: "how run scripts templates , partial views?".

i tried include scripts in section define in outer page, doesn't work, templates , partial view cannot include sections design (read this).

it doesn't work because js attaches timepicker html runs @ document.ready, content loaded via ajax loaded after document.ready

so need call method attaches timepicker again after ajax request has completed

you can try this:

$(document).ajaxcomplete(function(event, xhr, settings) {     alert('an ajax request completed');     $('.time-picker').timepicker(); }); 

Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -