I have a display for a collection of "SomeObject"
public List<SomeObject> SomeObjects
@Html.DisplayFor(m => m.SomeObjects)
This all works fine.. Then I had a requirement that meant I would need a second different display template for the same collection..
@Html.DisplayFor(m => m.SomeObjects, "NameOfTemplate")
I get the below message when I do this.. I have used named display templates before, but maybe it only works for primitive types - strings etc?
'System.Collections.Generic.List1[SomeObject]'
, but this dictionary requires a model item of type'SomeObject'
.
Adding code as request
"Test" DisplayTemplate
@model ViewModels.SomeObject
<p class="Namme">
<span>@Model.Name</span>
</p>
SimpleViewModel
public class SomeObject
{
public string Name { get; set; }
}
Property in ParentViewModel
public List<SomeObject> SomeObjects { get; set; }
Cshtml file..
@Html.DisplayFor(m => m.SomeObjects, "Test")
To me its a simple question, can a named template be used with a collection or not? Is it another limitation of mvc..
Cheers, John