I’ve got a situation where I want to show an object that isn’t attached to a model, but I’d like to specify metadata for it so that the templating system displays it as if it were a model property with specified metadata. Something like:
@Html.DisplayObject(obj, metadata) <--pseudocode
That is, I have a free object obj and I know how I want it to be displayed (usual metadata stuff like DisplayName, FormatString, UIHint, etc.), but this object isn’t attached to a model.
How can I hook into MVC’s default templating logic in this situation?
(The reason the object isn’t attached to a model, by the way, is that it’s loaded dynamically at runtime, so there’s no compile time place to add the property and decorate it with the metadata attributes. So I may really be asking about the right way to handle this situation.)
Not a brilliant answer by any means, but in the end I just manually implemented the UI that I needed, factored into useful partial views and helper methods, and it really wasn’t that hard. I also have complete control, which is nice.