Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

problem rendering user entered content

Vote:
 

Hi,

I was trying to create a simple page with a content editable part, but when I add some content to it and click publish, the page renders <>h1>h1instead of <>h1>Some entered texth1>.
 
When I go back to the CMS and click on the rich text editor, I can see Some entered text there, so I'm sure there is no information loss, the data is definitely saved.
I'm running Visual Studio Community 2015 on Windows 10 and Episerver 10.10
Here is my code:
------------ ApplePage.cs ------------
using System.ComponentModel.DataAnnotations;
using EPiServer.Core;
using EPiServer.DataAbstraction;
using EPiServer.DataAnnotations;
 
namespace Episerver10.Models.Pages
{
    [ContentType(DisplayName = "ArticlePage", GUID = "a8fe8485-587d-4880-b485-a52430ea55de",
        Description = "Basic page type for creating apple articles.")]
    public class ApplePage : PageData
    {
        [CultureSpecific]
        [Display(
            Name = "Main body",
            Description = "The main body editor area lets you insert text and images into a page.",
            GroupName = SystemTabNames.Content,
            Order = 10)]
        public virtual XhtmlString MainBody { getset; }
    }
}

------------ ApplePageController.cs ------------
using System.Web.Mvc;
using Episerver10.Models.Pages;
using EPiServer.Framework.DataAnnotations;
using EPiServer.Web.Mvc;
 
namespace Episerver10.Controllers
{
    [TemplateDescriptor(Default = true)]
    public class ApplePageController : PageController<>ApplePage>
    {
        public ActionResult Index(ApplePage page)
        {
            return View(page);
        }
    }
}

------------ Index.cshtml ------------
@model Episerver10.Models.Pages.ApplePage
 
@{
    Layout = null;
}
 
<>h1>@Html.PropertyFor(m => m.MainBody)h1>
---------------------------------------
 
What am I missing here?
Thanks in advance for your help.

#180435
Jul 10, 2017 14:30
Vote:
 

Hi,

I think the content is acutally rendered. But since it's XhtmlString it might not show up "correctly" in F12 tools since not all elements are valid to place inside an H1 tag. What happens if you render MainBody outside the H1?

I wouldn't recommend allowing formatting (XhtmlString) inside a header.

#180436
Jul 10, 2017 15:51
* 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.