OrchardCMS / OrchardCore

Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
https://orchardcore.net
BSD 3-Clause "New" or "Revised" License
7.39k stars 2.39k forks source link

Menu Theme Items of Items are inaccessible #11404

Open nejohannsen opened 2 years ago

nejohannsen commented 2 years ago

Describe the bug

When using menuitem alternate, Items of Items of the menuitem are not accessible. (You can loop through the Items under Model (MenuItems) but when working with one of those items it Items attribute is not accessible and gives the following error when working with it: error CS1061: 'object' does not contain a definition for 'Items' and no accessible extension method 'Items' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)

To Reproduce

Steps to reproduce the behavior:

  1. Set up a OrchardCore CMS project using nuget packages
    • OrchardCore.ContentManagement 1.3
    • OrchardCore.Application.Cms.Targets 1.3
  2. Setup CMS to use Blog recipe.
  3. Login in the admin area and go to MainMenu
  4. Set up Menu to have 3 levels of menu items
  5. Create a Theme project with the following nuget packages
    • OrchardCore.Theme.Targets 1.3
    • OrchardCore.ContentManagement 1.3
    • OrchardCore.DisplayManagement 1.3
    • OrchardCore.ResourceManagement 1.3
    • OrchardCore.Menu 1.3
  6. Add Theme projects as a reference in CMS projects
  7. Add a layout view that include the following line
    • <menu alias="alias:main-menu" cache-id="main-menu" cache-fixed-duration="00:05:00" cache-tag="alias:main-menu" />
  8. Add a _ViewImports.cshtml with the following lines
    • @inherits OrchardCore.DisplayManagement.Razor.RazorPage<TModel>
    • @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
    • @addTagHelper *, OrchardCore.DisplayManagement
    • @addTagHelper *, OrchardCore.ResourceManagement
    • @addTagHelper *, OrchardCore.Menu
    • '@using Microsoft.AspNetCore.Mvc.Localization'
  9. Add the alternate file "MenuItem-MainMenu.cshtml"
  10. Add the following lines of code to the above file:
    • @{TagBuilder topTag = new TagBuilder("div");
    • if ((bool)(Model.HasItems)){foreach (var item in Model.Items){
    • if ((bool)(item.HasItems)){ } (Set a debug point on this line)
    • }}}
    • @topTag
  11. when debugging try and work with item.Items
    • At this point you should get the following error:
    • CS1061: 'object' does not contain a definition for 'Items' and no accessible extension method 'Items' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)

Expected behavior

I would expect a list of objects that work like the list on object on the top level model.

sebastienros commented 2 years ago

Either the sub-items are not passed in the model recursively or the property is not the correct one. For the first option it can be checked in the Menu Shape cs file that generates it.