The <= causes the last closing brace inside of the script block to close the section. Change it to a just =, it's fine. Change it to <, and the block doesn't close at all.
I copied your code in a page of one of my projects...and it works! try to insert it into a fresh new project,...you will see that it works. Probably there is some other error in the page that causes this behaviour
It keeps getting more weird. If I add another line at the end of the above function, like this:
MyNamespace.MyFunction(i, id[0], id[1]);
I actually need another closing brace for the section, which ends up rendering a brace in the markup, which is also not desirable. Looks like I'm not the only one to see this:
please prepare a project with just 2 pages the Layout page and the page using the section...with no other code ...just the one needed to cause the issue to appear and send it to me. You can use the contact form of my blog.
However, this is the minimum to do before submitting a bug report to Microsoft, I read the discussion on StackOverflow...but strangely this proble never happened to me. So I "suspect" it just takes place if there is some "pervious small error". That is there
is something that Razor "tolerate" but that eventually may cause problems in some circumstances.
Similar error occurred when I converted an MVC3 project to MVC4 Developer preview.
It was also a javascript block inside an @section. The opening brace of the @section got closed by a closing brace inside the javascript block inside the @section.
Must be a bug in Razor2 since it was working fine in MVC3.
The work around I implemented was to move the script from the @section to the main section.
Jeff
Contributor
2733 Points
313 Posts
Razor bug: Javascript inside of a @section
Feb 23, 2012 09:29 PM|LINK
Consider the following block of code in a Razor view:
@section HeaderContent { <script type="text/javascript"> $(function () { for (var x = 0; x <= 5; x++) { // blah } $(".rate div").click(function () { // blah }); }); </script> }The <= causes the last closing brace inside of the script block to close the section. Change it to a just =, it's fine. Change it to <, and the block doesn't close at all.
POP Forums for MVC
JeffPutz.com
francesco ab...
All-Star
20912 Points
3279 Posts
Re: Razor bug: Javascript inside of a @section
Feb 23, 2012 10:05 PM|LINK
I copied your code in a page of one of my projects...and it works! try to insert it into a fresh new project,...you will see that it works. Probably there is some other error in the page that causes this behaviour
Mvc Controls Toolkit | Data Moving Plug-in Videos
Jeff
Contributor
2733 Points
313 Posts
Re: Razor bug: Javascript inside of a @section
Feb 23, 2012 10:20 PM|LINK
That may be true (I didn't supply the layout page, obviously), but that doesn't make it less broken.
POP Forums for MVC
JeffPutz.com
Jeff
Contributor
2733 Points
313 Posts
Re: Razor bug: Javascript inside of a @section
Feb 24, 2012 02:47 AM|LINK
It keeps getting more weird. If I add another line at the end of the above function, like this:
I actually need another closing brace for the section, which ends up rendering a brace in the markup, which is also not desirable. Looks like I'm not the only one to see this:
http://stackoverflow.com/questions/9366169/mvc4-razor-confused-about-braces
POP Forums for MVC
JeffPutz.com
francesco ab...
All-Star
20912 Points
3279 Posts
Re: Razor bug: Javascript inside of a @section
Feb 24, 2012 09:25 AM|LINK
please prepare a project with just 2 pages the Layout page and the page using the section...with no other code ...just the one needed to cause the issue to appear and send it to me. You can use the contact form of my blog.
Mvc Controls Toolkit | Data Moving Plug-in Videos
Jeff
Contributor
2733 Points
313 Posts
Re: Razor bug: Javascript inside of a @section
Feb 24, 2012 01:30 PM|LINK
Are you with Microsoft?
POP Forums for MVC
JeffPutz.com
francesco ab...
All-Star
20912 Points
3279 Posts
Re: Razor bug: Javascript inside of a @section
Feb 24, 2012 01:50 PM|LINK
No
However, this is the minimum to do before submitting a bug report to Microsoft, I read the discussion on StackOverflow...but strangely this proble never happened to me. So I "suspect" it just takes place if there is some "pervious small error". That is there is something that Razor "tolerate" but that eventually may cause problems in some circumstances.
Mvc Controls Toolkit | Data Moving Plug-in Videos
Jeff
Contributor
2733 Points
313 Posts
Re: Razor bug: Javascript inside of a @section
Feb 24, 2012 01:56 PM|LINK
I worked for Microsoft, and I have a repro solution. I asked a friend on the MVC team where to submit to, and he suggested posting it here and on SO.
POP Forums for MVC
JeffPutz.com
francesco ab...
All-Star
20912 Points
3279 Posts
Re: Razor bug: Javascript inside of a @section
Feb 24, 2012 02:11 PM|LINK
Does you repro solution....is very simply and just contains the section definition in the Layoiut page and the script causing the problem?
Or does your solution contains also other stuffs?
Mvc Controls Toolkit | Data Moving Plug-in Videos
jerryjoseph
Contributor
6740 Points
1257 Posts
Re: Razor bug: Javascript inside of a @section
Feb 24, 2012 07:28 PM|LINK
Similar error occurred when I converted an MVC3 project to MVC4 Developer preview.
It was also a javascript block inside an @section. The opening brace of the @section got closed by a closing brace inside the javascript block inside the @section.
Must be a bug in Razor2 since it was working fine in MVC3.
The work around I implemented was to move the script from the @section to the main section.
linkedin | twitter | www.jerryjoseph.net