将 jquery/javascript 与 asp.net MVC 视图分开?
我试图找到将我的脚本(即 jquery/javascript)与 asp.net MVC 中的视图(html)分开的最佳方法...
有人知道这样做的最佳方法吗?
我在我的视图中看到很多代码味道...
我过去使用过 JavascriptMVC,它做得非常好,也许将它们结合起来是个好主意,但考虑到我可能不会使用 javascriptmvc 的视图部分这不是正确的方向。
我真的很喜欢一些想法,并帮助找到使脚本远离视图等的最佳方法。
我正在使用许多外部模块,如 YUI 和 jquery,所以如果我需要采用另一个概念/layer - 我没有看到问题
期待任何帮助
谢谢
I am trying to found it the best way to keep my scripting i.e. jquery/javascript separate from my view (html) in asp.net MVC...
Does anyone have any idea the best way of doing this??
I am seeing alot of code smell in my views ...
I have used in the past JavascriptMVC which does a really good job and maybe its a good idea to combine them but considering i won't be using the view part of the javascriptmvc maybe its not the right direction to take..
I would really love some ideas and help on the best way of keeping scripting away from views etc..
I am using a number of external modules like YUI and jquery so if i need to employ another concept/layer - i don't see a problem
Look forward to any help
Thanksa
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我们可能(也可能没有)在如何将 javascript 与标记分开方面存在哲学差异。在我看来,只要 JavaScript 不嵌入到标记本身中,页面上就可以包含 JavaScript。如果可能的话,它应该在它自己的文件中关闭,但是当它直接引用特定于视图的元素时,我更喜欢将它放在视图文件本身中。
这是我使用的策略。
We may (or may not) have a philosophical difference in how separate to keep javascript from mark up. In my opinion, it's ok to have javascript on the page as long as its not embedded in the markup itself. If possible, it should be off in it's own files but when it directly references view-specific elements, I prefer to have it in the view file itself.
Here's the strategy that I use.
如果您将现有代码的代码片段粘贴到问题中,会更容易为您提供帮助。看看 这篇博文了解如何将 javascript 与 html 分开。
It will be easier to help you if you paste a code snippet of your existing code in the question. Look at this blog post to see how you can separate your javascript from your html.