Copied to clipboard

Flag this post as spam?

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


  • pbl_dk 150 posts 551 karma points
    Feb 18, 2018 @ 13:54
    pbl_dk
    0

    Partial View and Strongly Typed

    Hi there

    When I am using a partial view:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @{
     var selection = Model.Content.Site().Children.Where("umbracoFooterNav");
    }
    

    Umbraco returns in Visual Studio

    This method uses dynamics which will be removed in future versions, use strongly typed syntax instead''

    But I was under the impression that Model.Content was the strongly typed. What is wrong with my partial view?

  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Feb 18, 2018 @ 17:22
    Nik
    1

    Hi Elitenet,

    I'm not sure, but I think it is your use of Children and you use of Where that is resulting in the dynamic result.

    Model.content.Site(), is as far as I know returning an strongly typed implementation.

    Try changing Children to Children() and Where to a full LINQ expression.

    Thanks,

    Nik

  • Anders Bjerner 487 posts 2989 karma points MVP 7x admin c-trib
    Feb 18, 2018 @ 17:26
    Anders Bjerner
    101

    Hi,

    I can see that Nik was faster than me, but here goes anyways:

    Your view itself is actually fine. It is the Where method and the way that you use it that gives a warning, as it uses dynamics internally. Your code could be changed to:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @{
        var selection = Model.Content.Site().Children.Where(x => x.DocumentTypeAlias == "umbracoFooterNav");
    }
    

    Then you'll keep using the strongly typed models, and the warning is gone ;)

  • pbl_dk 150 posts 551 karma points
    Feb 18, 2018 @ 18:33
    pbl_dk
    0

    Okay thanks.

    I think I have mixed it up during an recode from @Currentpage to @Model. Makes sense that it originally was CurrentPage.

    Funny that the warning wasnt there originally. I think the warning came when I later upgraded whole umbraco code to 7.7.9.

    Well that's something to look out for when projects are going to be recoded to Strongly Types.

    thanks again :-)

Please Sign in or register to post replies

Write your reply to:

Draft