Asp.NET核心View组件视图未触发$(document).ready()

问题描述 投票:0回答:1

我是ASP.NET核心的新手。我正在使用基于条件的视图组件在组件文件夹下加载不同的视图。

<div class="container" id="patientLayout">
    @await Component.InvokeAsync("PatientView", new {model = Model})
</div>

 public async Task<IViewComponentResult> InvokeAsync(PatientTabViewModel model)
        {
            switch (model.Id)
            {               
                case 3:
                    PatientMessageViewModel msgModel=GetMessagesViewModel(model.PatientId);
                    return await Task.FromResult(View("_messages.cshtml", msgModel));
             }
        }

我在$(document).ready()_Messages.cshtml功能

<script type="text/javascript">    
    $(document).ready(function () {
        console.log('ready function fired');        
        }
    });
</script>

问题:这个就绪函数只是第一次被触发但是下一次它没有被触发,但断点在每次都被情况3击中。

能否为您提供一些信息/解决方案?

asp.net-core-mvc document-ready asp.net-core-viewcomponent
1个回答
0
投票

$( document ).ready()中包含的代码只有在页面文档对象模型(DOM)准备好执行JavaScript代码后才会运行。 $( window ).on( "load", function() { ... })中包含的代码将在整个页面(图像或iframe)(而不仅仅是DOM)准备就绪后运行。参考:$( document ).ready()

© www.soinside.com 2019 - 2024. All rights reserved.