How to render a page listing items(like news items) in a content area in EpiServer CMS

1.9k views Asked by At

I want to display a list of items (I am using a page listing block to display the list of pages.) in a content area.When I drag and drop the page type in content area I get an error stating"Castle.Proxies.ListingBlockProxy".

Below Is my code....

HomeBlockPage.cs

public class HomeBlocksPage : SitePageData
    {
        [Display(Name = "Main Listing", Description = "A listing of news pages", GroupName = SystemTabNames.Content, Order = 315)]
        public virtual ListingBlock MainListing { get; set; }
    }

View Model Class- ListingBlockModel.cs

public class ListingBlockModel
    {
        public ContentReference PageImage { get; set; }
        public IEnumerable<SitePageData> Items { get; set; }

    }

Index.cshtml of ListingBlock

@if (Model.Items != null) {
    foreach (var item in Model.Items)
    {
        <div class="list">

            <p><img src="@Url.ContentUrl(item.PageImage)"/></p>

            <h3>@Html.PageLink(item)</h3>

            @if (item.Property["MainBody"] != null)
            {
                @item.Property["MainBody"].Value
            }
            <hr />
        </div>
    } }

For displaying or rendering a list of items(list of pages) in a content area I have created a partial template for the pages.

PagePartialController.cs

  [TemplateDescriptor(Inherited = true)]
    public class PagePartialController : PartialContentController<HomeBlocksPage>
    {
        public  override ActionResult Index(HomeBlocksPage currentContent)
        {
            return PartialView("/Views/Shared/PagePartials/PagePartial.cshtml",currentContent);
        }
    }

PagePartial.cshtml

@model WesleyanSite.Models.Pages.HomeBlocksPage

    <div class="span12">
        <a href="@Url.PageUrl(Model.LinkURL)">
            @Model.MainListing
                </a>
    </div>

When I drag and drop the page in a content area in Edit Mode I am getting an error of "Castle.Proxies.ListingBlockProxy"

1

There are 1 answers

1
erik_nw On

Are you sure it's an error? MainListing is a property type of ListingBlock which becomes a ListingBlockProxy during runtime. If you only use @Model.MainListing in your markup, then the output probably will be "Castle.Proxies.ListingBlockProxy". If you try to display it with @Html.PropertyFor(x=>x.MainListing) instead it might work if the rest of the code is OK.