c# - Why is this throwing a string format exception -


i can't see wood trees.

why throwing string format exception?

 private const string googleanalyticsformat = @"<script type=""text/javascript"">                                                 var _gaq = _gaq || [];                                                  _gaq.push(['_setaccount', '{0}']);                                                 _gaq.push(['_trackpageview']);                                                  (function () {                                                     var ga = document.createelement('script');                                                     ga.type = 'text/javascript';                                                     ga.async = true;                                                     ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';                                                     var s = document.getelementsbytagname('script')[0];                                                     s.parentnode.insertbefore(ga, s);                                                 })();                                             </script>";  public static ihtmlstring rendergoogleanalytics<t>(this htmlhelpers<t> html, string trackingcode ) {     return html.raw(string.format(googleanalyticsformat, trackingcode)); } 

look @ bit of format string:

function () { ... } 

those braces being interpreted start/end of placeholders. need double them:

function () {{ ... }} 

so complete declaration be:

private const string googleanalyticsformat = @"<script type=""text/javascript"">     var _gaq = _gaq || [];     _gaq.push(['_setaccount', '{0}']);     _gaq.push(['_trackpageview']);     (function () {{         var ga = document.createelement('script');         ga.type = 'text/javascript';         ga.async = true;         ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';         var s = document.getelementsbytagname('script')[0];         s.parentnode.insertbefore(ga, s);     }})();     </script>"; 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -