Reputation: 1647
I have the simple partial view:
<div class="well">
<h3>
<strong>@Model.Name</strong>
<span class="pull-right label label- primary">@Model.AverageRaiting.ToString("# stars")</span>
</h3>
<span class="lead">@Model.Description</span>
@Html.DialogFormLink("Update", Url.Action("UpdatePhoto", new {id = @Model.PhotoId}), "Update Photo", Url.Action("Photo"))
@Html.Action("InitializeAlerts")
</div>
@section scripts{
<script src="~/Scripts/reload.alerts.js"></script>
}
Everything is ok by the first time. But after I replace the partial view by another one like above the custom script "reload.alerts.js"
doesn't work. This script is for @Html.Action("InitializeAlerts")
action.
InitializeAlerts
method just return a partial view named _Alert.
What shall I do to fix this problem?
Thanks.
Upvotes: 2
Views: 2148
Reputation: 12491
You shouldn't use @section scripts
in Partial Views.
Everything works fine if you render it in Main View becouse Razor knows where to put your script on _Layout
but when you refresh if you basically make ajax call and you get row html.
Since you get only Partial page without _Layout
Razor just cut this line so your script link doesn't even came to client.
You have 2 options:
@section scripts
and put your script link without it. I'm not sure, but i suspect that there is some possibilities when your script won't work this way either depending on how you write it.Upvotes: 4