Partial view model issues
# help-with-umbraco
s
I'm struggling a bit with porting over an umbraco 8 set of partial views. The models for each are based on the main InsightCarouselBase, mainly focussing on InsightsCarouselLatesat and InsightCarouselPicked. I'm not sure why they did it this way and I cannot get it to work at all. InsightCarouselBase
Copy code
csharp
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<Umbraco.Cms.Core.Models.Blocks.BlockListItem>;
@using ContentModels = Umbraco.Cms.Web.Common.PublishedModels;
@using Umbraco.Cms.Core.DependencyInjection;

@{
    var content = (ContentModels.InsightsCarouselBase)Model.Content;
    var settings = (ContentModels.InsightsCarouselBase)Model.Settings;
}

@if (content != null)
{
...
}
InsightCarouselLatest
Copy code
csharp
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<Umbraco.Cms.Core.Models.Blocks.BlockListItem>;
@using ContentModels = Umbraco.Cms.Web.Common.PublishedModels;

@{
    var content = (ContentModels.InsightsCarouselLatest)Model.Content;
    var settings = (ContentModels.InsightsCarouselLatest)Model.Settings;
}

@{
    Html.RenderPartial("~/Views/Partials/blocklist/components/InsightsCarouselBase.cshtml", content);
}
InsightCarouselPicked
Copy code
csharp
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<Umbraco.Cms.Core.Models.Blocks.BlockListItem>;
@using ContentModels = Umbraco.Cms.Web.Common.PublishedModels;

@{
    var content = (ContentModels.InsightsCarouselPicked)Model.Content;
    //var settings = (ContentModels.InsightsCarouselPicked)Model.Settings;
    content.Insights = content.PickedInsights.Cast<InsightsPage>().ToList();
}

@await Html.PartialAsync("~/Views/Partials/blocklist/components/InsightsCarouselBase.cshtml", content)
They are all based on InsightCarouselBase in ModelsBuilder but they can't seemingly speak to each other as they did in 8 due to the blockListItem stuff
I'm not sure I really understood the method or intent of the original developer
b
~~@Sandy you can use strong type version:
Copy code
@using ContentModels = Umbraco.Cms.Web.Common.PublishedModels;
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<Umbraco.Cms.Core.Models.Blocks.BlockListItem<ContentModels.InsightsCarouselLatest,ContentModels.InsightsCarouselLatest>>;

@{
    var content = Model.Content;
    var settings = Model.Settings;
}

@{
    Html.RenderPartial("~/Views/Partials/blocklist/components/InsightsCarouselBase.cshtml", content);
}
and I thinkn it is how it worked, but not sure~~ actually, Reading it again, Html.RenderPartial("~/Views/Partials/blocklist/components/InsightsCarouselBase.cshtml", content); so you pass only InsightsCarouselLatest into InsightsCarouselBase, but you need whole BlockListItem so you would need to pass like this:
Copy code
@{
    Html.RenderPartial("~/Views/Partials/blocklist/components/InsightsCarouselBase.cshtml", Model
);
}