asp.net mvc 多个局部视图文档就绪未调用
我有两个独立的视图,它们在各自的文档就绪函数中加载所需的数据。
我有一个主页,现在我想在其中显示两个视图。我将它们添加为部分视图,但问题是无论顺序是什么,都只会触发第一个部分视图的文档就绪。下面是首页的示例代码。仅调用任务视图的文档就绪。如果我颠倒顺序,则会调用活动视图文档就绪,但不会调用任务视图。
在其中一个链接 Stackoverflow 链接 中,我发现了一项建议创建一个通用的js文件,但我想保持逻辑的分离,让每个视图做自己的工作。
<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>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
多个
$(document).ready()
事件应该不是问题,请参阅这篇文章。问题可能出在其他地方,可能值得检查一下您是否在 jquery 中的部分或 javascript 变量中复制了元素 id,因为这可能会导致 jquery 的第二个块失败。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.