开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜