SaaS CMS has officially launched! Learn more now.

get html of XHTML property with nested block via ajax


Hi all,

I need to get XHTML property of my block using ajax.

If I add a different block into RTE, if I call
I get

as a part of html string and if I call
I get "".

What is the correct way of getting full correct html (including internal block html) from RTE property in ApiController?

Aug 04, 2016 14:26

Don't know if this is the correct way but I'm using this approach:

public class DummyController : Controller

public static class XhtmlStringExtensions
    public static string ToParsedHtmlString(this XhtmlString xhtmlstring)
        if (xhtmlstring == null || xhtmlstring.IsEmpty || string.IsNullOrWhiteSpace(xhtmlstring.ToHtmlString()))
            return string.Empty;

        var routeData = new RouteData();
        routeData.Values.Add("controller", "a");

        var hh = new HtmlHelper(new ViewContext()
            HttpContext = new HttpContextWrapper(HttpContext.Current),
            ViewData = new ViewDataDictionary(),
            TempData = new TempDataDictionary(),
            Controller = new DummyController(),
            RouteData = routeData
        }, new ViewPage());

        string result;

        using (var writer = new StringWriter())
            hh.ViewContext.Writer = writer;
            result = writer.ToString();

        return result;
Edited, Aug 12, 2016 13:43
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.