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

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

问题描述

我正在探索 ASP.NET MVC,我想添加 jQuery 以使站点具有交互性.我使用移植到 .Net 的 StringTemplate 作为我的模板引擎来生成 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?)

提前致谢:)

更新

请前往答案ASP.NET MVC 视图引擎比较问题以获得 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

最后我将把包括 JQuery 在内的 JavaScript 代码放在一个单独的脚本文件中,因此我不会担心 $ 混入模板文件中.

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("selector") 而不是 $("selector") 构造.

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

这是一篇关于 在 MVC 中使用 StringTemplate 作为视图引擎的好文章.

还有一个随附的开源引擎以及一些示例.

此外,如上所述,您可以修改您的类型词法分析器.(使其成为 $ 的替代字符).

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

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

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