jQuery的$是与StringTemplate.Net在ASP.Net MVC的冲突 [英] JQuery's $ is in conflict with that of StringTemplate.Net in ASP.Net MVC

查看:121
本文介绍了jQuery的$是与StringTemplate.Net在ASP.Net MVC的冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我探索ASP.NET MVC,我想补充的jQuery使网站的互动。我用StringTemplate的,移植到.NET,我的模板引擎来生成html并发送JSON。然而,当我查看网页,我无法看到它。调试完毕后,我意识到,$所使用的StringTemplate的访问财产等和jQuery使用它太来操纵DOM。哎呀,我已经看了其他模板引擎,其中大部分采用美元符号:(

I am exploring ASP.NET MVC and I wanted to add jQuery to make the site interactive. I used StringTemplate, ported to .Net, as my template engine to generate html and to send JSON. However, when I view the page, I could not see it. After debugging, I've realized that the $ is used by the StringTemplate to access property, etc and jQuery uses it too to manipulate the DOM. Gee, I've looked on other template engines and most of them uses the dollar sign :(.

有关ASP.Net MVC的任何替代模板引擎?我想保留的jQuery因为MSFT宣布,将在Visual Studio中使用(2008?)

Any alternative template engine for ASP.Net MVC? I wanted to retain jQuery because MSFT announced that it will used in the Visual Studio (2008?)

在此先感谢:)

更新

请转到<一个href=\"http://stackoverflow.com/questions/1451319/asp-net-mvc-view-engine-comparison/1451355#1451355\">the回答在 ASP.NET MVC视图引擎对比的问题COM prehensive ASP.NET MVC的模板引擎的列表,以及它们的优缺点

Please go to the answer in ASP.NET MVC View Engine Comparison question for a comprehensive list of Template engine for ASP.NET MVC, and their pros and cons

更新2

在最后我只是把JavaScript的code,包括JQuery的,在一个单独的脚本文件,所以我不会担心 $ 采风在模板文件。

At the end I'll just put the JavaScript code, including JQuery, in a separate script file, hence I wouldn't worry about the $ mingling in the template file.

更新3

改变了标题,以反映什么,我需要解决的问题。毕竟Y中的最佳X是非常主观的问题。

Changed the Title to reflect what I need to resolve. After all "The Best X in Y" is very subjective question.

推荐答案

当然,您可以将您的js逻辑放到.js文件。但是,如果你与你的意见StringTemplate的希望它内联,你可以使用\\ $构造逃脱它。

You can of course move your js logic into a .js file. But if you want it inline with your StringTemplate views, you can escape it using the \$ construct.

此外,你可以简单地使用了jQuery(选择),而不是$(选择)构建,如果你想避免转义语法。

In addition, you can simply use the jQuery("selector"), instead of $("selector") construct if you want to avoid the escaping syntax.

下面是一个使用StringTemplate的在MVC视图引擎上好文章

Here's a good article on using StringTemplate as a View Engine in MVC.

还有一个附带的开源引擎,具有一定的顺样品的。

此外,如上面提到的,你可以修改你的类型词法分析器。 (使它成为备选字符到$)。

Also, as mentioned above, you can modify your Type Lexer. (make it an alternate character to the $).

这篇关于jQuery的$是与StringTemplate.Net在ASP.Net MVC的冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆