While I don't necessarily know of an EPi-way, nor do I know the full context of your situation, we can sort of hack this together so it works...
public ActionResult Index(StandardPage currentPage)
{
var originalString = currentPage.MainBody;
HtmlHelper htmlHelper = new HtmlHelper(new ViewContext(ControllerContext, new RazorView(ControllerContext, "nothing", null, false, null), ViewData, TempData, new StringWriter()), new ViewPage());
var convertedString = htmlHelper.XhtmlString(currentPage.MainBody).ToString();
return View(currentPage);
}
Essentially what's it does is just create an HtmlHelper in the Controller, so then you at least have access to .XhtmlString(); This was pieced together and updated from this StackOverflow post. It might not be the best way, but it is at least one way to do it...
I was looking at the option of creating a HtmlHelper, but it just feels wrong with all the object instantiations needed in addition to all the nulls. Thanks, though! I appreciate the tip.
I guess my real question is: Is there a bug in the XhtmlString.ToHtmlString() method? I have seen it mentioned here in the forums earlier that it is supposed to resolve dynamic contentet rendering as well, while in the same thread it it stated that it doesn’t do it.
@Per Hemmingson:
While we wait for upgrade to cms 7.5, this is a working solution in my case:
I’m trying to use the .ToHtmlString() method on an instance of XhtmlString, but internal links does not render correctly. Is there another way to convert an XhtmlString to a string? I’m trying to use the .ToHtmlString() in the context of a controller, so I cannot use the HtmlHelper extension method .XhtmlString(...) without creating a helper instance and I don’t want to do that.
This is in MVC.