質問

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

役に立ちましたか?

解決

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));
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top