我应该在哪里包含来自 ASP.NET MVC 中主视图的 inerhits 视图的 javascript 参考?
我有一堆从主视图继承的页面。 其中一个页面我想使用一个流行的 jQuery 插件,名为“上传"。
我应该在哪里放置 Uploadify javascript 文件的引用? 我只需要它在一个小页面上,因此将其放置在主视图中似乎不合适。 将其放置在将使用此插件的继承视图的内容标记中是否可以“确定”?
I have a bunch of pages inheriting from a master view. One one of these pages I want to use a popular jQuery plugin called "Uploadify".
Where should I place the reference for the Uploadify javascript file? I only need it on one small page so it didn't seem right to place it in Master view. Is it 'Ok' to place it in the content tag of my inherited view that will use this plugin?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我知道执行此操作的最佳方法是在
MasterPage
的部分中添加
ContentPlaceHolder
,然后添加>
标记到Content
引用所有需要额外 javascript 的页面中的该部分(或 stylehseets,或其他......它肯定会增加额外的自由度)。在您的母版中:
由于默认情况下它是空的,因此您无需更改任何其他页面中的任何内容即可对母版进行此更改。
在需要额外 js 脚本的页面中:
The best way I know to do this is to add a
ContentPlaceHolder
in the<head>
section of theMasterPage
, and add the<script>
tags to aContent
referencing that section in all pages that need extra javascripts (or stylehseets, or whatever... It certainly adds an extra degree of freedom).In you master:
As it is empty by default, you don't have to change anything in any other pages to make this change to your master.
In your page that needs the extra js script:
在母版页上放置 ScriptManager 控件并在其中包含常用的 JS 文件:
放置 ScriptManagerProxy 控制您的内容页面(或任何用户控件),并在其中包含特定的 JS 文件:
编辑:我不确定这是否也适用于 ASP.NET MVC。
Put a ScriptManager control on your master page and include the commonly used JS files there:
Put a ScriptManagerProxy control on your content pages (or on any user controls) and include the specific JS files there:
EDIT: I'm not sure if this also works with ASP.NET MVC.
您可以在母版页的部分添加内容块。 这将对 js 文件的引用保留在文档头中,而不是文档正文中。
另外,如果您使用静态文档缓存,则将文档放入母版页还是视图中可能并不重要,特别是如果大多数人最终都会上传文档。 虽然这种方法可能会使首页加载速度稍微慢一些。
You could add a content block in the portion of your master page. That would keep the reference to your js file in the document head and out of the document body.
Also, if you use static document caching, it probably doesn't matter much whether you put the document in your master page or in the view, especially if most people will eventually upload a document. Although this approach may make the first page load a little bit slower.