Button block displaying as text

Vote:
 

Hello,

we are having an issue creating a button block. When we use the block on a page, it renders perfectly fine. However, it does not display as a button when used with another block, it just shows the name of the block as text. The view should render it as a button, but it isnt working on blocks for whatever reason. Does anyone know what could cause this block to render differently on blocks vs pages?

Our button model:

using CapCom.Epi.Core.Models.Base;
using EPiServer;
using EPiServer.DataAbstraction;
using System.ComponentModel.DataAnnotations;

namespace CapCom.Epi.Core.Models.Blocks
{
    /// <summary>
    /// Used to insert a link which is styled as a button
    /// </summary>
    [SiteContentType(GUID = "426CF12F-1F01-4EA0-922F-0778314DDAF0")]
    [SiteImageUrl]
    public class ButtonBlock : BaseBlock
    {
        [Display(Order = 1, GroupName = SystemTabNames.Content)]
        [Required]
        public virtual string ButtonText { get; set; }

        [Display(Order = 2, GroupName = SystemTabNames.Content)]
        [Required]
        public virtual Url ButtonLink { get; set; }
    }
}

Our button view:

@using CapCom.Epi.Core.Models.Blocks
@using EPiServer.ServiceLocation
@model ButtonBlock

@{ 
    var urlHelper = ServiceLocator.Current.GetInstance<UrlHelper>();
    var url = urlHelper.ContentUrl(Model.ButtonLink);
}
<p class="text-center"><a href="@url" class="btn btn-copper">@Model.ButtonText <i class="fa fa-chevron-right" aria-hidden="true"></i></a></p>
#228641
Oct 01, 2020 17:08
Vote:
 

Is the markup the same when used in other blocks?

Is the samme CSS available in both cases?

#228644
Oct 01, 2020 19:25
Vote:
 

Are you using ContentArea to render this block or using XhtmlString?

Make sure the parent property rendering it properly. Like-

 @Html.PropertyFor(m => m.MainContentArea)
#228966
Oct 06, 2020 7:29
Vote:
 

Thanks Ravindra, seemes like some places on the site were using PropertyFor and others were just using Model.Content, causing the inconsistant displaying... switching them all to Html.PropertyFor worked!

#229379
Oct 13, 2020 15:17
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.