Is there any out of the box code to serialize a model to Key Value Pairs using ModelMetaData?
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 KeyValueP开发者_如何学Goairs for the values of all of it's properties?
You could use the .ToDictionary() extension method from System.Linq?
Dictionary<string, object> dictionary = ViewData.ModelMetadata.Properties.ToDictionary(key => key.PropertyName, value => value.Model);
精彩评论