Domanda

I have an http server written in c# and I write some of the html in c#. I have problems with the quotes in writing some jQuery using XmlWiter.

this one works

xmlWriter.WriteRaw(@" $(document).ready(function (){  $("".fill-div"").attr(""href"",""Photo by Kelly Clark"");});");

But this one doesnt and its what I want to do

xmlWriter.WriteRaw(string.Format(@" $(document).ready(function (){  $("".fill-div"").attr(""href"",""{0}"");});", backUrl));

backUrl is a local variable which I get in my c# function and I need to set it as a link

È stato utile?

Soluzione

The error occurs because the first parameter of your string.Format already has curly braces to denote the function. You must escape the braces similar to what you did to the quotes:

xmlWriter.WriteRaw(string.Format(@" $(document).ready(function (){{  $("".fill-div"").attr(""href"",""{0}"");}});", backUrl));
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top