Closed joelmartinez closed 9 years ago
This seems to be a duplicate of https://github.com/Antaris/RazorEngine/issues/93 or at least related. Can you please reopen if this is not the case.
I can definitely see where that's similar, but in this case the first template (page-working
) successfully parses and runs (which I guess means that #93 is resolved in 3.4.2?). In this case the second template, page
, is the one that fails with that error, and it seems to only happen if there's html in there (as in, a script tag).
I also tried to use the Raw function to output the tag as a string, but got the same error ... not to mention I tried putting the closing brace on a new line to see if that would at least give me a workaround, but it still gave me the same error as well.
I'd re-open this, but github doesn't give me the option, I guess cause I'm not a collaborator :)
You are right, I just was looking at this at the moment and it seems to be either a bug in Microsoft.AspNet.Razor or by design and I found no quick workaround. Is similar code working in MVC templates?
I don't have a computer in front of at the moment, unfortunately. But I have definitely had a scripts section in previous mvc projects ... It's a major use case for razor sections so individual pages can add/customize the scripts on a page and have them at the end of the HTML/body.
I investigated this a bit more and it is in fact a bug in Microsoft.AspNet.Razor (please file a bug on them!) and ONLY happens with the EMPTY script tag. So the workaround is to use <script><script/>
instead of <script />
. Nice find though. Please comment when this workaround is not working for you.
Just to point out that I don't think self-closing script tags are valid HTML, and Razor is strict about the HTML that it will accept.
Wow, thanks for this. I read about the empty script tag a bit more and it blew my mind :). You should really stay away from it. However this still should be reported to Razor because at least the error message is not helping at all (and if you want to generate real XHTML this should work).
Wow ... I guess I'd always just had non-self closing script tags in my sections and just never really thought about it. Thanks for the clarification!
In the following example, the first section renders as expected.
While the second example fails with the following exception: