I know that ModelMetadata is used to bind values from a model to fields. Is there any out of the box MVC code that will take a model and use it's ModelMetadata to generate KeyValuePairs for the values of all of it's properties?
Asked
Active
Viewed 99 times
1 Answers
0
You could use the .ToDictionary() extension method from System.Linq?
Dictionary<string, object> dictionary = ViewData.ModelMetadata.Properties.ToDictionary(key => key.PropertyName, value => value.Model);

Stelloy
- 2,316
- 1
- 19
- 26
-
I would not be calling this from code where the ViewData is available. I guess the way to start is to construct the ViewData to get to that point. – Oved D Oct 05 '11 at 02:43