Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • suzyb 474 posts 932 karma points
    Nov 05, 2012 @ 11:30
    suzyb
    0

    Passing html as macro parameters

    For one of my razor macros I want to have the option to allow some before and after text which can, if necessary be html.  I have this working in XSLT by using disable-output-escaping however don't know how to get it working in razor.

    This is part of my macro

    string before = @Parameter.insertBefore;

    if (!string.IsNullOrEmpty(before))
    {
    @Html.Raw(before)
    }

    When I use Html.Raw it outputs the <p> on the page, the html has been encoded.  However if I don't use Html.Raw I get the text as it is sent to the parameter.

    Using Html.Raw

    &lt;p&gt;

    Not using Html.Raw

    &amp;lt;p&amp;gt;

    Does anyone know how to solve this.

  • Grant Thomas 291 posts 324 karma points
    Nov 05, 2012 @ 14:10
    Grant Thomas
    1

    If I understand you correctly, you could decode the input then output it raw:

    @Html.Raw(Server.HtmlDecode(before))
  • suzyb 474 posts 932 karma points
    Nov 05, 2012 @ 14:45
    suzyb
    0

    Doh!  I tried Html.Encode ;)

    Thanks, that works.

  • suzyb 474 posts 932 karma points
    Aug 16, 2013 @ 22:04
    suzyb
    0

    This doesn't seem to be working now in 6.1.3 using MVC :(

    This is the html output with the various encodings.  Can anyone advise how to fix.

    @Html.Raw(Server.HtmlDecode(Parameter.afterText)) = &lt;p&gt;
    @Server.HtmlDecode(Parameter.afterText) = &amp;lt;p&amp;gt;
    @Parameter.afterText = &amp;amp;lt;p&amp;amp;gt;


  • Pushpendra Singh 61 posts 116 karma points
    Oct 01, 2014 @ 12:22
    Pushpendra Singh
    0

    Hi Suzyb,

    Please try @Html.Raw(HttpUtility.HtmlDecode(before)).

    For me it's working in umbraco 6.2.1

Please Sign in or register to post replies

Write your reply to:

Draft