0
votes

Exist model - \Models\HeaderPart.cs. In Driver, want create CategoriesMenuDriver and use HeaderPart:

  public class CategoriesMenuDriver : ContentPartDriver<HeaderPart>
    {
    private readonly dynamic shapeFactory;
    private readonly IMenuAccessor menuAccessor;

    public CategoriesMenuDriver(
          IShapeFactory shapeFactory,
          IMenuAccessor menuAccessor)
      {
        this.shapeFactory = shapeFactory;
        this.menuAccessor = menuAccessor;
    }

    protected override DriverResult Display(HeaderPart part, string displayType, dynamic shapeHelper)
        {
          return this.ContentShape("Parts_CategoriesMenu", () => shapeHelper.Parts_CategoriesMenu(
            MenuItems: this.menuAccessor.GetMenu<NavigationMenuItem>("UserAccount")));
        }
    }

But in CategoriesMenu view

  var headerPart = (HeaderPart)Model.ContentItem.HeaderPart;

Model.ContentItem is null.

Can i get HeaderPart in View CategoriesMenu?

1

1 Answers

0
votes

You should be able to access the part like this:

HeaderPart part = Model.ContentPart;

Although Model.ContentItem shouldn't be null there, which is strange

EDIT If it also null you can try just setting it yourself:

protected override DriverResult Display(HeaderPart part, string displayType, dynamic shapeHelper)
{
        return ContentShape("Parts_CategoriesMenu", () => shapeHelper.Parts_CategoriesMenu(
            MenuItems: this.menuAccessor.GetMenu<NavigationMenuItem>("UserAccount"),
            ContentPart: part       
        ));
    }
}