简体   繁体   English

部分视图未共享视图中的脚本

[英]Script in view not shared by partial view

I have a .js page which I am including in my View using the &ltscript> tag.我有一个 .js 页面,我使用 &ltscript> 标签将其包含在我的视图中。 After an ajax call, I am rendering a partial view in the same view.在 ajax 调用之后,我在同一个视图中渲染了一个局部视图。 But the partial view was unable to access the methods from the .js file included in the view.但是局部视图无法访问视图中包含的 .js 文件中的方法。

I want to understand why the partial view was unable to access the method.我想了解为什么局部视图无法访问该方法。
Also, how much data can be shared between the view and the partial view?另外,视图和局部视图之间可以共享多少数据?

My understanding was, that, since the partial view is like the .ascx, it acts like a component of the view itself and has complete access to everything in the view (Apparently that's not the case).我的理解是,由于部分视图类似于 .ascx,它就像视图本身的一个组件,并且可以完全访问视图中的所有内容(显然情况并非如此)。

I was able to resolve the issue by including the same <script> tag (used in the view) in my partial view.我能够通过在我的局部视图中包含相同的<script>标记(在视图中使用)来解决这个问题。

you can append tha partial view html block in your parent page using JS.您可以使用 JS 在父页面中附加部分视图 html 块。 than you will be able to access components.比您将能够访问组件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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