在 ASP.NET MVC 1.0 母版页中使用 jQuery 的正确方法
这里有几个页面解决了 jQuery 与 .net 母版页的使用 - 更少的 re: .net MVC 应用程序中的 MVC 母版页。 但那些人似乎正在对 MVC 的预发布版本进行区分。
现在对于如何以及在何处包含该库以及我们需要注意哪些潜在问题是否达成了共识?
看起来事情似乎相当简单……将包含内容放入母版页的头部,然后就可以了。 (到目前为止对我来说)。 我想我正在寻找经验教训以及需要注意的事项 - 我还没有触及部分视图和 ajax 之类的功能。
谢谢
There are a few pages here addressing usage of jQuery with .net masterpages - fewer re: masterpages in MVC in .net MVC apps. But those few seem to be making distinctions re pre-release versions of MVC.
Is there now a consensus regarding how and where to include the lib and what potential problems we need to be aware of?
It _looks as though things are fairly straight forward...put the include in the masterpage's head and stuff works. (as it has for me _so far). I guess I'm looking for lessons learned and what to watch out for - i haven't scratched features like partial views and ajax yet.
thx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如 Iconic 提到的,您可以随意使用 jQuery,但您认为合适。 我会在规划我的网站后决定这一点 - 如果只有一两个页面使用 jQuery,我只会将其包含在其中。 如果我的整个网站都依赖它(例如,像 SO 那样),我会将其包含在我的母版页中。 它所需要的只是一个简单的标签,唯一需要注意的可能是一些带宽,如果您预计只有几个页面有大量流量,而这不使用 jQuery。
As Iconic mentioned, you're free to use jQuery however you see fit. I would decide this after planning my site - if only a page or two are using jQuery, I would include it in them only. If my whole site relies on it (like SO does, for example), I would include it in my masterpage. All it takes is a simple tag, and the only thing to watch out for is perhaps some bandwidth, if you expect to have much traffic to only several pages, which does not use jQuery.
包含 jQuery 并没有什么神奇的方法。 由于它是一个客户端库,因此将其包含在母版页中可以轻松地从任何视图或部分视图连接到 $(document).ready。
一旦它位于页面顶部,就可以在任何时候添加插件或挂钩事件。 这样,您就可以将特定于您的应用程序的 jQuery 封装在视图或部分视图本身中。
There's no magic way to include jQuery. Since it's a client-side library, including it in the master page makes it easy to hook into $(document).ready from any view or partial view.
Once it's at the top of your page, it's trivial to include plugins or hook into events at any point. That way, you can encapsulate jQuery that is specific to your application in the view or partial view itself.