This project is read-only.

ModelBinder and MetaDataAttribute Problem


Modelbinder can not load meta data from another class
in entityframework EDMX files create model file automatically and we need to add meta data class

i fix in my source based on codes from here:

changes: (ModelBinder.cs)
 static void BindControl(object obj, Control page)
if (obj == null)

            var metadataAttrib = obj.GetType().GetCustomAttributes(typeof(MetadataTypeAttribute), true).OfType<MetadataTypeAttribute>().FirstOrDefault();
            var buddyClassOrModelClass = metadataAttrib != null ? metadataAttrib.MetadataClassType : obj.GetType();

            var properties = buddyClassOrModelClass.GetProperties(BindingFlags.Instance | BindingFlags.Public);
and some where that load complex type


mahdiit wrote Mar 23, 2013 at 7:37 PM

you need to change every four section that load Properties with this function:
private static Type GetClassOrModelType(Type baseType)
            var metadataAttrib = baseType.GetCustomAttributes(typeof(MetadataTypeAttribute), true).OfType<MetadataTypeAttribute>().FirstOrDefault();
            return metadataAttrib != null ? metadataAttrib.MetadataClassType : baseType;
and then change
var properties = type.GetProperties();
to this
var properties = GetClassOrModelType(type).GetProperties();

wrote Apr 1, 2013 at 7:34 AM

wrote Nov 29 at 12:17 PM