Thursday, January 26, 2017

Using DisplayFor on model's nested properties

Problem:
My MVC model has a property which is a Generic list of another class.  I needed to iterate across this collection using Razor Syntax.

Solution:
I found a great solution at stackoverflow


You have to iterate your list and call display for on each item:
@foreach (var summary in Model.CollectionClass)
{
    @Html.DisplayFor(x => summary.Balance)
}


Source:
http://stackoverflow.com/questions/25061233/using-displayfor-on-models-nested-properties

accepted