It looks like a magic for me that @Html.DisplayForModel() can render the markup automatically wi开发者_JS百科thout requiring me to explicitly pass the data model to it.
How does @Html.DisplayForModel() know the underlying data model?
I believe it uses @Html.ViewData.ModelMetadata internally to get the necessary information about your model. ModelMetadata has information about all the properties in your model, validation attributes, etc. etc.
Yes, esentially it iterates
<% foreach (var prop in ViewData.ModelMetadata.Properties.Where(pm => pm.ShowForDisplay                         && !ViewData.TemplateInfo.Visited(pm))) { %>
See Brad Wilson's excellent blog http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-3-default-templates.html
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论