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