Quantcast
Channel: C1 CMS Foundation - Open Source on .NET
Viewing all articles
Browse latest Browse all 2540

New Post: Strange issue using a static helper method - string result has it's ampersands parsed.

$
0
0
Hi all!

I am experience a very stange issue.

I have a set of static classes which I use to manage some Urls with. I am trying to render one of these Urls as a parameter for a javascript file.

For e.g. in my MasterLayout.cshtml for my C1 Page, I have the following snippet (note that it is surrounded by CDATA)
<![CDATA[
<script type="text/javascript">
  MyJavascript.Widget.init({
    widgetSourceUrl: "@(MyUrlHelper.WidgetSourceUrl())"
  });
</script>
]]>
The helper has a source similar to:
public static class MyUrlHelper
{
  public static string WidgetSourceUrl()
  {
    return "/widget/source?param1=foo&param2=bar";
  }
}
However, once rendered, the html output becomes:
<script type="text/javascript">
  MyJavascript.Widget.init({
    widgetSourceUrl: "/widget/source?param1=foo&amp;param2=bar"
  });
</script>
The & got parsed into a &

I thought that the CDATA wrapper would stop this. The stranger thing is, when I manually put the Url into my master layout, like so:
<script type="text/javascript">
  <![CDATA[
  MyJavascript.Widget.init({
    widgetSourceUrl: "/widget/source?param1=foo&param2=bar"
  });
  ]]>
</script>
It actually renders the output correctly as:
<script type="text/javascript">
  MyJavascript.Widget.init({
    widgetSourceUrl: "/widget/source?param1=foo&param2=bar"
  });
</script>
???? confused face!

Is Composite somehow intercepting the string return from my helper method and doing a transform on the string?? Wizardry! I am at a loss for explanations here.

Has anyone else out there experienced something like this?

Viewing all articles
Browse latest Browse all 2540

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>