In Orchard, how do I include a javascript file in my partial view that's loaded from an ajax call?
Here's what I've tried:
@{Script.Include("ownerInfo.js");}
Orchard completely ignores this if the view is hit from an ajax call
Edit: The below works, although including scripts by hand is not ideal. See Piedone's example below for a better alternative.
<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:
// 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.
You could do the following:
Include the script with Orchard and display the head and/or foot scripts' shape in your view:
Display.HeadScripts() Display.FootScripts()
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.