开发者

Is there any out of the box code to serialize a model to Key Value Pairs using ModelMetaData?

开发者 https://www.devze.com 2023-04-09 06:52 出处:网络
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

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消