Copied to clipboard

Flag this post as spam?

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


  • Fran Hoey 15 posts 27 karma points
    Dec 13, 2011 @ 09:42
    Fran Hoey
    1

    Media item html tags stripped off in Razor and escaped in xslt

     

    I've set up a system where an xml doc is uploaded via a specific Media Type. The AfterSave event parses the XML (using xslt) to convert it to HTML. The HTML is then stored in a RichText Property on the media item.

    This works well, until I try to output the converted HTML to a page. Razor macros strip the HTML tags and xslt macros xml encode it.

    I can handle the xslt (at a push), but really I want to use Razor, and the behaviour seems very odd. @Html.Raw has no effect.

    This is my AfterSave event code:

    private void Media_AfterSave(umbraco.cms.businesslogic.media.Media sender, umbraco.cms.businesslogic.SaveEventArgs e)
    {
        string html = string.Empty;
        string error = string.Empty;
        if ((sender.ContentType.Alias == "Newsletter") )
        {
    
            Property fileprop = sender.getProperty("umbracoFile");
    
            Property htmlprop = sender.getProperty("html");
    
            try
            {
                htmlprop.Value = ConvertToHtml(fileprop.Value.ToString());
            }
            catch (Exception ex)
            {
                htmlprop.Value = string.Format("ERROR: {0}", ex.Message);
                Log.Add(LogTypes.Error, sender.Id, string.Format("Message: {0}. StackTrace:{1}", ex.Message, ex.StackTrace));
            }
        }
    }

    And this is the data stored in cmsPropertyData following a save:

    <div class="doc">    <p><span style="">This is my test doc … </span></p>    <p></p>    <p></p>    <p><span style="">Lets</span><span style=""> see what is looks like</span></p>  </div>

     

    If I can get this to work it will be soo cool, maybe even my first published package. Any help greatly appreciated.

    Thanks,
    Fran

  • Funka! 398 posts 661 karma points
    May 19, 2012 @ 01:56
    Funka!
    0

    Did you ever figure this out?  I posted this two days ago which seems like the same problem : http://our.umbraco.org/forum/developers/razor/31803-Richtext-editor-property-on-a-Media-type-HTML-tags-are-stripped-when-rendered

    This behavior is indeed a bit... odd.

  • Fran Hoey 15 posts 27 karma points
    May 23, 2012 @ 09:30
    Fran Hoey
    0

    In the end I gave up and used xslt!

     

    Boo

  • Razvan 36 posts 67 karma points
    Jul 08, 2012 @ 14:07
    Razvan
    0

    This is indeed a serious limitation/bug of umbraco/razor relation. We cannot use XML/HTML datatypes in media items. 

  • Funka! 398 posts 661 karma points
    Jul 10, 2012 @ 21:46
    Funka!
    0

    My new working theory is that the HTML is stripped upon being either cached and/or retrieved by the UmbracoExamine engine when dealing with Media.

    I'm thinking the Razor engine is not the one responsible for this, I'm just not sure how to prove it (or fix it).

    Thank you!

Please Sign in or register to post replies

Write your reply to:

Draft