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?
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.
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.
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?
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:
This should also work for any custom extended properties you've made to your docType models.
I have class below, I want to convert or parse the MenuLinks alias to my class model.
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.
is working on a reply...