Well, I think the ASP.NET MVC team released a pretty significant bug in the developer preview for asp.net mvc 4, or I’m doing something stupid… Here’s the issue and steps to reproduce.
- Create a new MVC 4 mobile application
- create a new section in the layout (ex. @RenderSection(“head”,false))
- in the controller action just throw a Message into the ViewBag
- then in a view that uses the main layout, add the following code below.
@section head {
$(function() {
var newVariableName = "@(ViewBag.Message)";
});
}
You’ll notice that the razor parser actually thinks that the section has been completed for the jquery on dom loaded ending brace instead of the section’s ending brace. I tried the exact same code in an asp.net MVC 3 application and it worked with no issues.
Has anyone else come across this bug in the ASP.NET MVC 4 Developer Preview?
A quick hack to solving this issue is to use < text > blocks < /text > around the java script. Here’s what it might look like until the ASP.NET MVC team resolves this bug.