Copied to clipboard

Flag this post as spam?

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


  • Robert J. Bullock 386 posts 405 karma points
    Mar 10, 2011 @ 17:46
    Robert J. Bullock
    0

    Returning HTML from RichText Editor?

    I am using umbraco v 4.7.0.RC (Assembly version: 1.0.4077.25828) but when I use @item.bodyText in a Razor Macro, I get back the umbraco.MacroEngines.DynamicXml, not the HTML. How to fix this?

  • Sebastiaan Janssen 5061 posts 15544 karma points MVP admin hq
    Mar 10, 2011 @ 18:12
    Sebastiaan Janssen
    0

    What is "item" supposed to be? A full code sample would be helpful. 

    When you're just trying to display the bodyText of the current page you would do something like this:

    <div class="article">
     @Html.Raw(Model.bodyText)
    </div>

    Doing Html.Raw here so that you don't just get the html encoded version, but the full html output.

  • Robert J. Bullock 386 posts 405 karma points
    Mar 10, 2011 @ 18:48
    Robert J. Bullock
    0

    Oh, I tried that, but I get this error:

    The best overloaded method match for 'System.Web.WebPages.Html.HtmlHelper.Raw(string)' has some invalid arguments

    Not sure what's up with that... Here's my complete macro:

    <umbraco:Macro  runat="server" language="cshtml">
    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{ var numberOfItems = 10; }
    <div class="donors-tab-container">
    @foreach (var item in @Model.Children) {
      <div id="@item.Id" class="tab-content">
        <p>@Html.Raw(item.bodyText)</p>
      </div>
    }
    </div>
    </umbraco:Macro>

  • Robert J. Bullock 386 posts 405 karma points
    Mar 10, 2011 @ 19:20
    Robert J. Bullock
    0

    Got it working with this syntax:

    @Html.Raw(item.GetProperty("bodyText").ToString())

  • Sebastiaan Janssen 5061 posts 15544 karma points MVP admin hq
    Mar 11, 2011 @ 17:02
    Sebastiaan Janssen
    0

    Your example code works just fine but you need to make sure to pass an empty string to Html.Raw if the bodyText is empty:

    <div class="donors-tab-container">
     @foreach (var item in @Model.Children) {
      <div id="@item.Id" class="tab-content"> 
        <p>@Html.Raw(item.bodyText.ToString())</p> 
      </div> 
     } 
    </div>


  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies