I using String.Format this way:
String.Format("$(function() { $('{0}').menu(); });", "blaId");
I get an exception:
An exception of type 'System.FormatException' occurred and was caught.
How can I fix this?
You should escape { characters like this: {{, unless they are a part of placeholders like {0}.
String.Format("$(function() {{ $('{0}').menu(); }});", "blaId");
You have an invalid index value inside your curly braces. String.Format recognises this as a place holder for the formatting.
{ $('{0}').menu(); }
To resolve this, use double curly braces to escape:
String.Format("$(function() {{ $('{0}').menu(); }});", "blaId");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With