public static void IntoModelMetadata(ModelMetadata metadata, string dataSourceName, string key = "DataSource") { if (string.IsNullOrWhiteSpace(dataSourceName)) { dataSourceName = metadata.PropertyName; } string dataSourceViewDataKey = DataSourceHelper.GetDataSourceViewDataKey(dataSourceName); metadata.AdditionalValues.Add(key, dataSourceViewDataKey); }
public static string GetDataSourceViewDataKey <TModel, TProperty>(Expression <Func <TModel, TProperty> > expression) { string name = null; if (expression.Body.NodeType == ExpressionType.MemberAccess) { MemberExpression memberExpression = (MemberExpression)expression.Body; name = ((memberExpression.Member is System.Reflection.PropertyInfo) ? memberExpression.Member.Name : null); } return(DataSourceHelper.GetDataSourceViewDataKey(name)); }