是否有任何开箱即用的代码使用ModelMetaData将模型序列化为键值对?

时间:2011-09-28 18:24:14

标签: asp.net-mvc modelmetadata

我知道ModelMetadata用于将模型中的值绑定到字段。是否有开箱即用的MVC代码,它将采用模型并使用它的ModelMetadata为其所有属性的值生成KeyValuePairs?

1 个答案:

答案 0 :(得分:0)

您可以使用System.Linq中的.ToDictionary()扩展方法吗?

Dictionary<string, object> dictionary = ViewData.ModelMetadata.Properties.ToDictionary(key => key.PropertyName, value => value.Model);