简体   繁体   English

Orchard - 在部分视图中包含Javascript文件

[英]Orchard - Including Javascript files in partial views

In Orchard, how do I include a javascript file in my partial view that's loaded from an ajax call? 在Orchard中,如何在部分视图中包含一个从ajax调用加载的javascript文件?

Here's what I've tried: 这是我尝试过的:

@{Script.Include("ownerInfo.js");}

Orchard completely ignores this if the view is hit from an ajax call 如果从ajax调用中查看视图,Orchard会完全忽略它

Edit: The below works, although including scripts by hand is not ideal. 编辑:以下工作,虽然手工包含脚本并不理想。 See Piedone's example below for a better alternative. 请参阅下面的Piedone示例,以获得更好的选择。

<script type="text/javascript" src="./Modules/ModuleName/Scripts/script.js"></script>

I think this is by design. 我认为这是设计上的。 If you look at Orchard.UI.Resources.ResourceFilter (this is the filter adding those shapes to the layout that render static resources) it contains the following check: 如果你看一下Orchard.UI.Resources.ResourceFilter(这是将这些形状添加到呈现静态资源的布局的过滤器),它包含以下检查:

// should only run on a full view rendering result
        if (!(filterContext.Result is ViewResult))
            return;

This prevents it from injecting the shapes into the layout if the action result is eg a PartialViewResult. 如果动作结果是例如PartialViewResult,这可以防止它将形状注入布局。

You could do the following: 您可以执行以下操作:

  • Insert the script "by hand" “手动”插入脚本
  • Include the script with Orchard and display the head and/or foot scripts' shape in your view: 在Orchard中包含脚本并在视图中显示头部和/或脚部脚本的形状:

    Display.HeadScripts() Display.FootScripts() Display.HeadScripts()Display.FootScripts()

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

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