I'm not actually sure this is c# per se but I'm working in a .cshtml file (in episerver).
I'm setting a string variable that includes quotes. This is a simplified version:
@{
var backgroundcontent = "class='background' data-transition='mytransition'";
if (Model.CurrentBlock.Photo) {
backgroundcontent = "class='photo' data-transition='none'";
}
}
When this is rendered in the page, I'm getting '
which is great if I'm rendering it inside a tag, but not when I need it in the tag itself.
Am I stuck with the html quotes (and have to do something more complicated like setting two variables for the attributes), or is there a way to override them?
Try Html.Raw(backgroundcontent);
, this should prevent default string escaping.