@Editable does not HtmlEncode

We are using Sitecore 7 and MVC + Glass.mapper to build a new site.

Strange thing is that when we use @Editable(x => x.SectionTitle), when in Edit mode the SectionTitle field's content gets HtmlEncoded, but not in preview or normal mode. (So if there is "" in the title field, it is output as &lt;H1&gt; in edit mode, but as <H1> in normal and preview)

If we use @HTML.Sitecore().Field("SectionTitle") however, it always gets HtmlEncoded, and that is the behaviour we are looking for when using a single line text field...

Is this a Glitch in Glass?


Mike, this is the cshtml code:

@using Sitecore.Mvc
@using CZ.OnlineIntegratie.Web.Core.Sc.Extensions
@inherits Glass.Mapper.Sc.Web.Mvc.GlassView<CZ.OnlineIntegratie.Web.Core.SitecoreModels.GlassModels.Sectie>

<section>
    <H2> @Html.Sitecore().Field("SectieTitel")</H2>
    <h2>@Editable(x => x.SectieTitel)</h2>
    @Html.Sitecore().DynamicPlaceholder("sectieInhoud")
</section>

We generate the models with T4 and TDS, this is the Sectie class generated:

namespace CZ.OnlineIntegratie.Web.Core.SitecoreModels.GlassModels
{
    /// <summary>
    /// ISectie Interface
    /// <para></para>
    /// <para>Path: /sitecore/templates/CZ NL/Site/Content/Sectie</para>    
    /// <para>ID: 1760c3c6-a623-404a-98be-a0d4335a03cc</para>   
    /// </summary>
    public interface ISectie : IGlassItem // , ITagging
    {
            /// <summary>
        /// The SectieTitel field.
        /// <para></para>
        /// <para>Field Type: Single-Line Text</para>       
        /// <para>Field ID: 2e364ec5-f0d4-4f16-baa3-fa9207f89cf6</para>
        /// <para>Custom Data: </para>
        /// </summary>
        string SectieTitel  {get; set;}

        }


    /// <summary>
    /// Sectie
    /// <para></para>
    /// <para>Path: /sitecore/templates/CZ NL/Site/Content/Sectie</para>    
    /// <para>ID: 1760c3c6-a623-404a-98be-a0d4335a03cc</para>   
    /// </summary>
    [SitecoreType(TemplateId="1760c3c6-a623-404a-98be-a0d4335a03cc")]
    public partial class Sectie  : GlassItem, ISectie 
    {
                private string _sectieTitel;

        /// <summary>
        /// The SectieTitel field.
        /// <para></para>
        /// <para>Field Type: Single-Line Text</para>       
        /// <para>Field ID: 2e364ec5-f0d4-4f16-baa3-fa9207f89cf6</para>
        /// <para>Custom Data: </para>
        /// </summary>
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Team Development for Sitecore - GlassItem.tt", "1.0")]
        [SitecoreField("SectieTitel")]
        public virtual string SectieTitel  
        {
            get { return _sectieTitel; } 
            set { _sectieTitel = value; }
        }

            private object /* UNKNOWN */ _tags;

        /// <summary>
        /// The Tags field.
        /// <para></para>
        /// <para>Field Type: Multilist with Search</para>      
        /// <para>Field ID: 3a837ce8-7a1b-4cbf-8be9-9cebbdf1c48a</para>
        /// <para>Custom Data: </para>
        /// </summary>
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Team Development for Sitecore - GlassItem.tt", "1.0")]
        [SitecoreField("Tags")]
        public virtual object /* UNKNOWN */ Tags  
        {
            get { return _tags; } 
            set { _tags = value; }
        }


        public static string TemplateId { get { return "1760c3c6-a623-404a-98be-a0d4335a03cc"; } }
    }

}

In the cshtml you can see that I use the Sitecore MVC field and the glass way. Glass does not output htmlencoded strings while sitecore MVC does in preview and normal...

Erwin

Answers


I have made a blog post that detail how you could solve this problem:

http://glass.lu/2013/11/21/EncodedStrings.html

I will be adding the EncodedString type to the next Glass.Mapper.Sc release, thanks for the suggestion.


Need Your Help

Do I always have to write a converter for date-formatting?

wpf data-binding xaml format converter

I often use textboxes in my wpf-projects which are bound to datetime-propertys. I want to format the dates into the german format dd.MM.yyyy.

Finding image type from NSData or UIImage

iphone ios uiimage nsdata persist

I am loading an image from a URL provided by a third-party. There is no file extension (or filename for that matter) on the URL (as it is an obscured URL). I can take the data from this (in the for...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.