3

I am not able to make changes to the text in the simple text fields using the Experience Editor. Is there some way to modify my code to make it work with the Experience Editor?

View

@model MyCompanyBootstrap.Models.HomePageViewModel

<div class="container">
    <div class="page-title">
        <h1>@Html.Raw(Model.SampleItem.Title.Raw)</h1>
    </div>

    <div class="generic-content">
        <div class="body-content hidden-xs">
            <p>
                @Html.Raw(Model.SampleItem.Text.Raw)
                <br><br>
            </p>
        </div>

        <div class="body-content-small visible-xs">
            <p>
                @Html.Raw(Model.SampleItem.Text.Raw)
                <br><br>
            </p>
        </div>
    </div>
</div>

Controller

public ActionResult Index()
{
    var dataSourceId = RenderingContext.CurrentOrNull.Rendering.DataSource;
    var dataSource = Context.Database.GetItem(dataSourceId);
    var homePageViewModel = new HomePageViewModel();
    homePageViewModel.RotatorContentItems = dataSource.Children.Select(c => new RotatorContentItem(c)).ToList();
    homePageViewModel.SampleItem = RenderingContext.CurrentOrNull.PageContext.Item;
    return View(homePageViewModel);
}

Model

public class HomePageViewModel
{
    public List<RotatorContentItem> RotatorContentItems { get; set; }
    public SampleItem SampleItem { get; set; }
}

Sample Item

public partial class SampleItem : CustomItem
{

public static readonly string TemplateId = "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}";


#region Boilerplate CustomItem Code

public SampleItem(Item innerItem) : base(innerItem)
{

}

public static implicit operator SampleItem(Item innerItem)
{
    return innerItem != null ? new SampleItem(innerItem) : null;
}

public static implicit operator Item(SampleItem customItem)
{
    return customItem != null ? customItem.InnerItem : null;
}

#endregion //Boilerplate CustomItem Code


#region Field Instance Methods


public CustomTextField Title
{
    get
    {
        return new CustomTextField(InnerItem, InnerItem.Fields["Title"]);
    }
}


public CustomTextField Text
{
    get
    {
        return new CustomTextField(InnerItem, InnerItem.Fields["Text"]);
    }
}


#endregion //Field Instance Methods
}

RotatorContentItem

public partial class RotatorContentItem : CustomItem
{

public static readonly string TemplateId = "{E493DF4A-E97E-49B5-BF9F-F70397EA8D21}";


#region Boilerplate CustomItem Code

public RotatorContentItem(Item innerItem) : base(innerItem)
{

}

public static implicit operator RotatorContentItem(Item innerItem)
{
    return innerItem != null ? new RotatorContentItem(innerItem) : null;
}

public static implicit operator Item(RotatorContentItem customItem)
{
    return customItem != null ? customItem.InnerItem : null;
}

#endregion //Boilerplate CustomItem Code


#region Field Instance Methods


public CustomTextField Title
{
    get
    {
        return new CustomTextField(InnerItem, InnerItem.Fields["Title"]);
    }
}


public CustomTextField SubTitle
{
    get
    {
        return new CustomTextField(InnerItem, InnerItem.Fields["Sub Title"]);
    }
}


public CustomImageField ImageLarge
{
    get
    {
        return new CustomImageField(InnerItem, InnerItem.Fields["Image Large"]);
    }
}


public CustomImageField ImageSmall
{
    get
    {
        return new CustomImageField(InnerItem, InnerItem.Fields["Image Small"]);
    }
}


public CustomGeneralLinkField Link
{
    get
    {
        return new CustomGeneralLinkField(InnerItem, InnerItem.Fields["Link"]);
    }
}


public CustomCheckboxField IsOverlayBlack
{
    get
    {
        return new CustomCheckboxField(InnerItem, InnerItem.Fields["Is Overlay Black"]);
    }
}


#endregion //Field Instance Methods
}

1 Answer 1

8

Yes - you are using the Raw Value when you do @Html.Raw(Model.SampleItem.Text.Raw) - this bypasses the field renderer and so will not be editable in the Experience Editor.

Instead of .Raw use .Rendered - this will render the field using Sitecore's Field Renderer and add the page editable parts.

@Html.Raw(Model.SampleItem.Text.Rendered)
5
  • Okay, the field allows me to change the text. But, the save button is disabled.
    – ADH
    Commented Oct 6, 2016 at 20:19
  • Should I post that problem as a separate question?
    – ADH
    Commented Oct 6, 2016 at 20:20
  • 1
    Not yet - check your permission levels
    – Richard Seal
    Commented Oct 6, 2016 at 20:21
  • I am logged in as the admin.
    – ADH
    Commented Oct 6, 2016 at 20:21
  • 3
    Try to search for an answer before just posting a new question here. There are a few things that could cause that issue. Someone has probably had the same issue and its online somewhere :)
    – Richard Seal
    Commented Oct 6, 2016 at 20:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.