简体   繁体   中英

asp.net mvc multiple partial view document ready is not called

I have two self contained views that loads the required data in their respective document ready functions.

I have a home page where I now want to show the two views. I am adding them as partial views but the issue is only the first partial view's document ready is triggered no matter what the order is. Below is the sample code of the Home page. Only the task view's document ready is called. If I reverse the order, the activity view document ready is called but not the task view.

In one of the links Stackoverflow link I found a suggestion to create a common js file but I want to maintain the separation of logic and let each view do its own work.

<div style="width:300px">
@if (Request.IsAuthenticated)
{
    @Html.Partial("~/Views/Task/Index.cshtml")
}
</div>
<div style="width:300px">
@if (Request.IsAuthenticated)
{
    @Html.Partial("~/Views/Activity/Index.cshtml")
}
</div>

Multiple $(document).ready() events should not be a problem, see this article . The issue is probably somewhere else, it is probably worth checking to see if you are duplicating element ids within your partials or javascript variables within the jquery as this could cause the second block of jquery to fail.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM