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

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.