U4-1078 - @Node.RTEParam vs @Media.RTEParam inconsistent in razor implementation, one returns html the other stripped html

Created by Mike Chambers 25 Oct 2012, 09:24:50 Updated by Sebastiaan Janssen 31 May 2013, 16:02:02

Duplicates: U4-644

adding in a doesn't seem to have been resolved in u4.8

originally documented here..[http://umbraco.codeplex.com/workitem/30377] (Timothy I'm hijacking your in depth explanation I hope you don't mind)

I am working on the 4.7.1 branch. (still present in the v4.8 release)

I'm not sure I understand the behavior going on with MediaById and NodeById in regards to Razor and retrieving nodes from the Content and Media sections.

If I create a media type called LibraryItem that contains a RTE called LibraryContent and then create an item under Media of that type with some Html in the RTE, when I then attempt to pull that Html using a Razor macro (with the LibraryId parameter being the Id of the node, simplified below by replacing the parameter with the actual numeric Id) I get text only with the Html stripped out:

@Model.MediaById(Parameter.LibraryId).LibraryContent --> LibraryContent (a RTE) returns text, not html...

So, the contents of the RTE are:

some html
is in here

-- For media nodes where id 1621 is a media node with a media type that contains a RTE --

@Model.MediaById(1621).LibraryContent

returns text with html stripped: some htmlis in here

@Model.NodeById(1621).LibraryContent

returns nothing.

-- For content nodes where id 1625 is a content node of with a document type that contains a RTE --

@Model.MediaById(1625).LibraryContent

returns nothing.

@Model.NodeById(1625).LibraryContent

returns the correct html.


So, based on these results, it seems that NodeById applies only to the Content section and MediaById applies only to the Media section but Razor gets the incorrect results from a RTE in the media section. I should note that enclosing "@Model.MediaById(1621).LibraryContent" with Html.Raw() does not work. The Html appears to be already stripped by the time the data gets to the macro (although I'm not sure how to verify that).

It seems to me that getting the contents of a RTE from a custom media type node in the media section should return Html not text.

Thanks for any help in advance!

Timothy

Comments

Mike Chambers 25 Oct 2012, 14:22:04

Managed to work around this with a little hackery... in that we want all our RTE to be parsed into System.Xml.XmlDocuments anyway...

[RazorDataTypeModel("5e9b75ae-face-41c8-b47e-5f4b0fd82f83")] public class RichTextEditorSmall : IRazorDataTypeModel { public object PropertyData; public int CurrentNodeId; public bool Init(int CurrentNodeId, string PropertyData, out object instance) { this.PropertyData = PropertyData; this.CurrentNodeId = CurrentNodeId;

        // huge hack as assumes all richtext editors are called "content" :-(
        instance = UmbracoJPT.Utils.Util.ParseRTEPropertyAsXml(CurrentNodeId, "content");
        return true;
    }
}

bit of a hack but ok in our case as only one RTE on media/document nodes... both named ("content")

I did try adding an AsXml method, but think the razorcore translates to htmlString so getting a method exception:-(


Matt Darby 22 Feb 2013, 13:02:17

Still have this problem in Umbraco v6.


Gareth Evans 31 May 2013, 00:04:43

Fixed in 4.11.9 by Shannon


Priority: Normal

Type: Bug

State: Fixed

Assignee:

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions: 4.8.0

Due in version: 4.11.9

Sprint:

Story Points:

Cycle: