JQuery's $ is in conflict with that of StringT

2020-01-27 03:10发布

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 :(.

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?)

Thanks in Advance :)

Update

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

Update 2

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.

Update 3

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

14条回答
何必那么认真
2楼-- · 2020-01-27 03:13

In case you want to stick with StringTemplate (ST) see this article from the ST wiki. You may also change the behaviour totally by editing Antlr.StringTemplate.Language\DefaultTemplateLexer.cs and replacing the "$" with what you want.

查看更多
Explosion°爆炸
3楼-- · 2020-01-27 03:15

I would highly recommend Spark. I've been using it for awhile now with jQuery and haven't ran into a single issue so far.

查看更多
霸刀☆藐视天下
4楼-- · 2020-01-27 03:15

Perhaps jQuery.noConflict will work for you

查看更多
手持菜刀,她持情操
5楼-- · 2020-01-27 03:15

Have a look at the mvccontrib project. They have 4 different view engines at the moment which are brail, nhaml, nvelocity and xslt.

http://www.codeplex.com/MVCContrib

查看更多
别忘想泡老子
6楼-- · 2020-01-27 03:23

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.

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

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

There's also an accompanying OpenSource engine, along with some samples.

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

查看更多
兄弟一词,经得起流年.
7楼-- · 2020-01-27 03:24

You could try jsRepeater.

查看更多
登录 后发表回答