I have a partial view which contains some JS, but seems it's never fired :
My Partial :
@model List<String>
@if (Model != null)
{
foreach (var item in Model)
{
<button id="application-@item" type="button" class="btn btn-default" onclick="showUses('@item')">@item</button>
}
}
@section scripts
{
<script type="text/javascript">
$(function () {
alert("plop");
});
</script>
}
Main view :
...
<div class="col-md-6 ">
<h2>Applications</h2>
<div id="Application" class="btn-group-vertical" role="group">
@Html.Partial("_ApplicationPartial", null, new ViewDataDictionary())
</div>
</div>
...
@section scripts
{
<script type="text/javascript">
$(function () {
$('[id^=univers]').click(function () {
var selectedButton = $(this).attr('id');
var selectedUniverse = selectedButton.substring(selectedButton.indexOf('-') + 1, selectedButton.lenght);
$("#Application").load('@(Url.Action("Application", "UseAndNeed", null, Request.Url.Scheme))?idUniverse=' + selectedUniverse);
});
});
</script>
}
The alert is supposed to be fired when the page is loaded, and as well when i use the load() to refresh the partialView content.
Is it the normal behaviour, JS is never fired in a partialView or do i miss something?