How to render the properties of the view model's base class first when using ViewData.ModelMetadata.Properties for a generic edit view
When I use the ViewData.ModelMetadata.Properties
in order to loop the properties (with an additional Where(modelMetadata => modelMetadata.ShowForEdit && !ViewData.TemplateInfo.Visited(modelMetadata))
), and thereby create a generic edit view, the properties of the view model's base class are rendered last.
Is it possible to use a clever OrderBy() or is there another way to first get the properties of the base class, and then the sub class'?
Reverse
won't do the trick since the ordering of each class' properties is perfectly fine.
A workaround would of course be composition + delegation,开发者_运维问答 but since we don't have mixins, it's too un-DRY IMHO, why I seek a better solution if possible.
Looking at ViewData.ModelMetadata.Properties I dont see any information that shows if a property is part of the Model class or of its Superclass.
One way would be to put an attribute on the properties of the Superclass. If this is a attribute "DisplayMeAtTheTop" it could be used by other properties too, that have to be on top.
I went with another solution that doesn't use inheritance.
The case is; based on a type, only a sub-set of the properties should be editable.
I solved it by defining a set of property lambda expressions for each type.
精彩评论