private IEnumerable <object> GetParentValues(CascadingDropDownAttribute child, ViewDataDictionary viewData)
        {
            var parentMetadata = ModelMetadata.FromStringExpression(child.ParentName, viewData);

            var viewModelType  = parentMetadata.ContainerType;
            var parentProperty = parentMetadata.PropertyName;

            var properties = GetPropertyInfo(viewModelType, viewData, 0);

            var theProperty = properties.FirstOrDefault(x => x.Name == parentProperty);

            var cascadingAttr = theProperty.GetCustomAttribute <CascadingDropDownAttribute>();

            if (cascadingAttr != null)
            {
                foreach (var obj in GetParentValues(cascadingAttr, viewData))
                {
                    yield return(obj);
                }
            }
            yield return(parentMetadata.Model);
        }
Esempio n. 2
0
        private IEnumerable<object> GetParentValues(CascadingDropDownAttribute child, ViewDataDictionary viewData)
        {
            var parentMetadata = ModelMetadata.FromStringExpression(child.ParentName, viewData);

            var viewModelType = parentMetadata.ContainerType;
            var parentProperty = parentMetadata.PropertyName;

            var properties = GetPropertyInfo(viewModelType, viewData, 0);

            var theProperty = properties.FirstOrDefault(x => x.Name == parentProperty);

            var cascadingAttr = theProperty.GetCustomAttribute<CascadingDropDownAttribute>();
            if (cascadingAttr != null)
            {
                foreach (var obj in GetParentValues(cascadingAttr, viewData))
                {
                    yield return obj;
                }
            }
            yield return parentMetadata.Model;
        }
        private static void SetViewdataWithValues(CascadingDropDownAttribute attr, string name, IDictionary <string, object> viewData, params object[] values)
        {
            var viewDataKey = "DDKey_" + name;

            viewData[viewDataKey] = viewData[viewDataKey] ?? attr.GetMethodResult(values);
        }
Esempio n. 4
0
 private static void SetViewdataWithValues(CascadingDropDownAttribute attr, string name,
     IDictionary<string, object> viewData, params object[] values)
 {
     var viewDataKey = "DDKey_" + name;
     viewData[viewDataKey] = viewData[viewDataKey] ?? attr.GetMethodResult(values);
 }