Copied to clipboard

Flag this post as spam?

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


  • Rene M. Macalisang 7 posts 76 karma points
    Mar 06, 2024 @ 17:17
    Rene M. Macalisang
    0

    BlockListItem to Custom Model

    I Have navigation menu and i want to parse this output to a custom model so its essay to call those properties, Is it possible to handle this result to a custom model?

    enter image description here

  • Danine Noble 82 posts 368 karma points
    Mar 08, 2024 @ 16:04
    Danine Noble
    0

    Are you meaning a strongly-typed model; not custom? If you want to access fields'n properties of a document type you just need to use strongly typed models.

    From your example, this would be making the 'item' as the 'MainNavLinkItem' type.

    Something like:

    foreach (var item in nav)
    {
      // 'MainNavLinkItem' = whatever the name of your docType model is
      // 'navLinkItem' is just a variable to output if it's a successful cast; name however you like
      if (item is not MainNavLinkItem navLinkItem)
      {
        continue;
      }
    
      // then you can use 'navLinkItem' as a strongly typed variable and access all of that model's properties
    }
    

    This should also work for any custom extended properties you've made to your docType models.

  • Rene M. Macalisang 7 posts 76 karma points
    Mar 08, 2024 @ 16:11
    Rene M. Macalisang
    0

    I have class below, I want to convert or parse the MenuLinks alias to my class model.

    public class MainNavigationLinkItemModel : BaseNodeViewModel
     {
         public Link Link { get; set; }
    
         public string Title { get; set; }
    
         public IList<MainNavigationSubMenuModel> SubMenus { get; set; } = new List<MainNavigationSubMenuModel>();
    
         public string FlyOutCaption { get; set; }
    
         public string FlyoutTitle { get; set; }
    
         public string FlyOutDescription { get; set; }
    
         public Link FlyOutButton { get; set; }
    
     }
    

    By the way I am using umbraco 13. Is there any way or method that I can use? I don't want to parse it manually.

Please Sign in or register to post replies

Write your reply to:

Draft