janjongboom / Moth

Moth has all the awesomness Steve Souders thaught you about fast websites, but fully integrated in your ASP.NET MVC project!
27 stars 5 forks source link

Inline Scripts for Razor #19

Closed kijanawoodard closed 12 years ago

kijanawoodard commented 12 years ago

I'm having trouble getting inline scripts to work in Razor.

Compiler Error Message: CS1056: Unexpected character '$'

I translated the code from the inline scripts page: https://github.com/janjongboom/Moth/wiki/Inline-script

@using(Html.BeginScript(ScriptPositionEnum.EndOfPage)) { $(function () { $('p').addClass('yellow'); }); }

janjongboom commented 12 years ago

You have to put <text> and </text> around your javascript block in Razor unfortunately :-( See the Mvc3.Demo folder.

kijanawoodard commented 12 years ago

Got it. Thanks.

I added a web forms partial to get by the issue, but that just got deleted. :-)

I'm using knockout js and I wanted to apply bindings from several partials all at once. Needs to be "last", but with razor views and Moth, the "parent" scripts were being written first even if I "registered" them after RenderBody. I vaguely remember that as a general razor thing and I thought maybe Moth inline scripts will get me through.....and it worked!

Kijana

On Fri, Jun 22, 2012 at 4:54 AM, Jan Jongboom < reply@reply.github.com

wrote:

You have to put <text> and </text> around your javascript block in Razor unfortunately :-( See the Mvc3.Demo folder.


Reply to this email directly or view it on GitHub: https://github.com/janjongboom/Moth/issues/19#issuecomment-6504322