My display template "PlanAlternate":
@model MyPlan
<div class="span4 compare-column compare-column1">
<div class="compare-row-plan">
<h3>@Model.Plan.Name</h3>
</div>
@foreach (var benefit in Model.Plan.Benefits)
{
<div class="compare-row-benefit-description">
@benefit.Description
</div>
}
<div class="compare-row-submit">
<input class="btn" type="submit" value="Apply Now" />
</div>
</div>
My View that uses the display template:
@model IEnumerable<MyPlan>
<div class="span9 compare-data-wrapper">
@Html.DisplayForModel("PlanAlternate")
</div>
This throws an exception:
The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[MyPlan]', but this dictionary requires a model item of type 'MyPlan'.
HOWEVER, If I rename the display template from PlanAlternate.cshtml to MyPlan.cshtml and use
@Html.DisplayForModel()
Everything works just fine. Can you help me understand why this is happening?
Thanks!
EDIT:
If I do exactly as described above where the display template file name matches the view model name, but I pass the view name ("MyPlan") to DisplayForModel, it still throws an exception!! Calling DisplayForModel with no arguments works. This seems very, very weird to me. Almost like a bug but I'm sure it's just something I don't understand.