Reputation: 7656
I can't get nested DisplayForModel to work at all, I have tried everything. All display templates are in the correct DisplayTemplates folder.
The ratings file just never gets called, although if I do @Html.DisplayFor(x => x.Likes, "Ratings")
it would call it correctly but obviously only pass the likes property through, anyone know what is going on here?
Index file, works fine:
@model IList<UploadedSongViewModel>
<section id="music-grid">
<div class="container">
@Html.DisplayForModel() //Works fine
</div>
</section>
UploadedSongViewModel template:
@model UploadedSongViewModel
<div class="col-md-5ths col-xs-6">
@Html.DisplayForModel("Ratings") //Never calling the ratings display template
</div>
Ratings file:
<span class="like-percentage" data-likes="@Model.Likes" data-dislikes="@Model.Dislikes">
<i class="fa fa-thumbs-up" data-toggle="tooltip" data-placement="bottom" title="Like percentage">
</i>
</span>
Upvotes: 1
Views: 595
Reputation: 54628
Never calling the ratings display template
That is by design. The MVC engine tags each object it renders by type by setting the TemplateInfo.Visited()
method. If it's already visited the model, it won't visit it again (to avoid stack overflows / infinite loops). Simply changing it to the following should work (can't test atm).
@model UploadedSongViewModel
<div class="col-md-5ths col-xs-6">
@Html.DisplayFor(m => m, "Ratings")
</div>
Upvotes: 1