mvcplayer - Error while parsing a javascript function with array

Topics: MVC, Troubleshooting
Jun 13, 2011 at 3:52 PM
Hi Team,

when i use this javascript-code, i get an error from mvcplayer:


Error: Ein Name darf nicht mit dem Zeichen ' ', hexadezimaler Wert 0x20, beginnen. Zeile 51, Position 32.
Error details:
Failed to get value for function 'Composite.AspNet.MvcPlayer.Render'
Ein Aufrufziel hat einen Ausnahmefehler verursacht.
MvcPlayer: failed to parse result markup as xml
Ein Name darf nicht mit dem Zeichen ' ', hexadezimaler Wert 0x20, beginnen. Zeile 51, Position 32.

function highlightDays(date) {
            for (var i = 0; i < dates.length; i++) {
                if (dates[i] == date) {
                    return [true, "highlight"];
                }
            }
            return [true, ""];
        }
Jun 13, 2011 at 7:27 PM

The rason is found:

 

for (var i = 0; i < dates.length; i++) {

 

The lt character will be interpreted as xml-tag!

try
{
    return XDocument.Parse(sbHtml.ToString());
}
catch (Exception ex)
{
    throw new InvalidOperationException("MvcPlayer: failed to parse result markup as xml", ex);
}

 

 

One Solution is to exclude the javascript in separate files.

Jun 13, 2011 at 7:36 PM
Edited Jun 13, 2011 at 7:37 PM

Remember you should also be able to use CDATA to enclose your text that should be ignored by the XML parser

http://www.w3schools.com/xml/xml_cdata.asp