Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • bh 408 posts 1395 karma points
    Aug 08, 2022 @ 17:49
    bh
    0

    Can a Blocklist Component view Load a PartialView?

    Can a Blocklist Component view Load a PartialView? If so, what does that look like?

    I've got this on my component view...

    @await Html.PartialAsync("../../EventsGrid.cshtml", Model, new ViewDataDictionary(ViewData) { { "skipX", 2 }, { "takeX", 3 }, { "exclude", "" } })
    

    ...and I'm getting this error...

    Cannot bind source type Umbraco.Cms.Core.Models.Blocks.BlockListItem ... to model type Umbraco.Cms.Core.Models.PublishedContent.IPublishedContent

  • Søren Kottal 702 posts 4497 karma points MVP 5x c-trib
    Aug 09, 2022 @ 06:15
    Søren Kottal
    1

    Looks like your are sending a model of type BlockListItem into a view requiring an IPublishedContent type model.

    In your example, you could send Model.Content, which is IPublishedElement, but you would need to update your EventsGrid view to take IPublishedElement instead of IPublishedContent. They are similar, so if you are not relying on stuff on the model, like Url, and tree things, it should be an easy switch.

  • bh 408 posts 1395 karma points
    Aug 09, 2022 @ 13:01
    bh
    0

    @SorenKottal My partial does need the tree.

  • Søren Kottal 702 posts 4497 karma points MVP 5x c-trib
    Aug 09, 2022 @ 13:06
    Søren Kottal
    0

    Can you show your partial? Do you need the tree based on the passed in model (you can't do that)

  • bh 408 posts 1395 karma points
    Aug 09, 2022 @ 13:30
    bh
    0

    Thanks for your response @SorenKottal Here's the relevant server-side code on my partial:

    @using ContentModels = Umbraco.Cms.Web.Common.PublishedModels;
    @inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage
    @{
        Layout = null;
    
        var skipX = ViewData["skipX"];
    
        var takeX = ViewData["takeX"];
    
        var exclude = ViewData["exclude"];
    
    
        IEnumerable<IPublishedContent> _events = Umbraco.ContentSingleAtXPath("//home").DescendantsOfType("EventDetail").Where(x => x.Name != exclude.ToString()).Skip((int)skipX).Take((int)takeX).Where(x => x.IsVisible()).OrderBy(x => x.Value("StartDate"));
    
    
    }
    

    I tried inheriting IPublishedElement but, then I couldn't do Umbraco.ContentSingleAtXPath.

  • Søren Kottal 702 posts 4497 karma points MVP 5x c-trib
    Aug 10, 2022 @ 06:21
    Søren Kottal
    100

    Try @inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<IPublishedElement>

  • bh 408 posts 1395 karma points
    Aug 10, 2022 @ 12:45
    bh
    0

    @Soren Kottal many thanks!

    @inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<IPublishedElement> on my Partial View

    and @await Html.PartialAsync("/Views/Partials/EventsGrid.cshtml", Model.Content, new ViewDataDictionary(ViewData) { { "skipX", 2 }, { "takeX", 3 }, { "exclude", "" } }) on my block list component view.

    That combo did the trick.

    Thank you!

Please Sign in or register to post replies

Write your reply to:

Draft