Setting the values for a content part

Topics: Customizing Orchard
Jan 28, 2015 at 6:52 PM
Edited Jan 28, 2015 at 6:55 PM
I have a content part with the following Display function
protected override DriverResult Display(BannerWidgetPart part, string displayType, dynamic shapeHelper)
        {
            var publishedBannerItems = _contentManager.Query(VersionOptions.Published, "BannerItem").List();
            List<string> publishedBannerItemList = new List<string>();
            foreach (var bannerItem in publishedBannerItems)
            {
                publishedBannerItemList.Add(((dynamic)bannerItem).BannerItem.Fields[2].Path);
            }

            part.CurrentBannerPath = publishedBannerItemList[0];
            part.PreviousBannerPath = publishedBannerItemList[0];

            return ContentShape("Parts_BannerWidgetPart",
                () => shapeHelper.Parts_BannerWidgetPart(Model: part));
        }
My Editor does not do anything to set the values for this part as it doesn't require user input. I'm just grabbing a list of image paths that are connected to a published banner item and then setting the part's values to a random path (currently I've just hard coded the value to whatever is the first item in the list instead of randomizing it - one step at a time). When I do this however the value is null when I try to access it in the view using @Model.CurrentBannerPath am I missing something? I've never tried to set the values of a part in the database this way as I usually need to use the editor view to accept input from the user for the values in which case I use razor's textboxfor and similar items. Thank you.

Edit: I have run the debugger and part.CurrentBannerPath and part.PreviousBannerPath both have a string value "/Media/Default/Banner%20Images/masthead%20(1).jpg"
Jan 28, 2015 at 7:02 PM
I changed
return ContentShape("Parts_BannerWidgetPart",
                () => shapeHelper.Parts_BannerWidgetPart(Model: part));
to
return ContentShape("Parts_BannerWidgetPart",
                () => shapeHelper.Parts_BannerWidgetPart(CurrentBannerPath: part.CurrentBannerPath));
and it fixed the problem I can now access it using @Model.CurrentBannerPath Can anyone explain this to me? I feel like I am missing something about how passing in the "Model" works.