2

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"

Aman Mehta
  • 29
  • 1
  • 10
  • What does you `ListingBlockModel Controller` look like? – Eric Herlitz Jun 19 '16 at 07:43
  • @EricHerlitz I do not have listingblockmodel controller. I have created ListingBlockController public class ListingBlockController : BlockController { public override ActionResult Index(ListingBlock currentBlock) { var contentRepository =ServiceLocator.Current.GetInstance(); var model = new ListingBlockModel(); if (currentBlock.RootPage != null) { model.Items = contentRepository.GetChildren(currentBlock.RootPage);} else {model.Items = null; } return PartialView(model); } } – Aman Mehta Jun 20 '16 at 06:40
  • @EricHerlitz and this is my ListingBlock.cs public class ListingBlock : BlockData { [Display(GroupName = SystemTabNames.Content, Order = 200)] public virtual PageReference RootPage { get; set; } } – Aman Mehta Jun 20 '16 at 06:41

1 Answers1

1

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.

erik_nw
  • 837
  • 5
  • 11