我知道ModelMetadata用于将模型中的值绑定到字段。是否有开箱即用的MVC代码,它将采用模型并使用它的ModelMetadata为其所有属性的值生成KeyValuePairs?
答案 0 :(得分:0)
您可以使用System.Linq中的.ToDictionary()扩展方法吗?
Dictionary<string, object> dictionary = ViewData.ModelMetadata.Properties.ToDictionary(key => key.PropertyName, value => value.Model);