0

In the following block, why do we need the //<![CDATA[ ... //]]> block?

@using(Script.Foot()) {
    <script type ="text/javascript">
    //<![CDATA[
    $(document).ready(function () { 
        alert('page loaded');
    });
    //]]>
    </script>
}

Related Questions:

What is the meaning of CDATA

Community
  • 1
  • 1
Shaun Luttin
  • 133,272
  • 81
  • 405
  • 467

1 Answers1

0
  • Why CDATA sections? CDATA sections tell the XML parser to read the characters without interpreting them as element or entity markup.
  • Why leading // marks? We introduce the CDATA opening and closing tags with // marks, so the JavaScript parser ignores the CDATA tags.
  • Why .cshtml but not .html? The .cshtml pages, which ASP.NET MVC uses, are XML based whereas .html pages are not.

References

CData Sections (MSDN)

What is the meaning of CDATA

Community
  • 1
  • 1
Shaun Luttin
  • 133,272
  • 81
  • 405
  • 467