List<T> property is empty in view but not in Driver

Topics: Troubleshooting, Writing modules
Jun 22, 2011 at 10:17 PM

I have a widget who's Display method in the driver sets a property which is a List<T> (just some view model class that I'm mapping some properties from content items into). The Display method looks like this:


var items = //code that gets the List<MyViewModel> objects here

return ContentShape("Parts_FeaturedItems",
    () => shapeHelper.Parts_FeaturedItems(Items: featuredItems, Foo: "bar"));

I've debugged the Display method to verify that the items variable does in fact contain the items I expect.

Then, in my "Parts_FeaturedItems" view template I'm simply trying to loop over the items to create a <ul> like this:

    @foreach (MyViewModel item in Model.Items) {

The problem is that the Model.Items list is always empty in the view, even though I can see it's populated in the driver. Any ideas? Am I overlooking something stupid here? The Foo property I added to the shape was just a sanity check to make sure that Model was being passed to the template properly, which it is as "bar" renders on the view.

Jun 22, 2011 at 10:20 PM

Random guess: can you try to rename Items to something else and see if that makes a difference?

Jun 23, 2011 at 3:12 AM

Well, whaddya know, that was the problem. I take it "Items" is a special property that Orchard automatically adds to the Model for ContentShapes, or something along those lines? I guess that could make sense - since it's dynamic my Items must have gotten overwritten later in the pipeline. Thanks!