Reputation:
I have some Display Templates in my ASP.NET MVC project. Right now i can use them like so:
@Model MyModel
@Html.DisplayFor(x => x.PropertyName)
What I'd like to do is just loop through the object graph and do this dynamically:
@Model MyModel
foreach(var property in MyModel.GetType().GetProperties()){
@Html.DisplayFor(/*Any way to do this?*/)
}
Any ideas?
Upvotes: 1
Views: 870
Reputation: 24754
If I remember correctly this is exactly what DisplayForModel
already does:
@Html.DisplayForModel(yourModel);
Upvotes: 1
Reputation:
http://weblogs.asp.net/rashid/archive/2010/02/09/asp-net-mvc-complex-object-modelmetadata-issue.aspx
with thanks to Jeremy Skinner for finding that for me :)
Upvotes: 0