protected override object CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType)
        {
            // Only leaf nodes have Valuie property
            var valueKey      = bindingContext.ModelName + ".Value";
            var valueProperty = bindingContext.ValueProvider.GetValue(valueKey);

            if (valueProperty != null)
            {
                var model = new FilterLeafNode();
                bindingContext.ModelMetadata = ModelMetadataProviders.Current.GetMetadataForType(() => model, typeof(FilterLeafNode));
                return(model);
            }
            else
            {
                var model = new FilterRootNode();
                bindingContext.ModelMetadata = ModelMetadataProviders.Current.GetMetadataForType(() => model, typeof(FilterRootNode));
                return(model);
            }
        }
        /// <summary>
        /// Add a new root node to a given parent node in the scaffold model provided with the parent node name
        /// </summary>
        /// <param name="scaffoldModel"></param>
        /// <param name="rootNode"></param>
        /// <param name="parentNodeName"></param>
        /// <returns></returns>
        public static FilterScaffoldModel <T> AddRootNoodeToParent <T>(this FilterScaffoldModel <T> scaffoldModel, FilterRootNode rootNode, string parentNodeName)
        {
            var parentNode = scaffoldModel.GetRootNodeByName(parentNodeName);

            parentNode.Nodes.Add(rootNode);

            return(scaffoldModel);
        }
        /// <summary>
        /// Adds a root node to another root node given with the specific parent node id
        /// </summary>
        /// <param name="scaffoldModel">The scaffold model object we are extending</param>
        /// <param name="rootNode">The new root node to be added to the scaffold model hirearchy</param>
        /// <param name="parentNodeId">The internal id of the root node to which we will add the new root node</param>
        /// <returns></returns>
        public static FilterScaffoldModel <T> AddRootNodeToParent <T>(this FilterScaffoldModel <T> scaffoldModel, FilterRootNode rootNode, int parentNodeId)
        {
            var parentNode = scaffoldModel.GetRootNodeById(parentNodeId);

            parentNode.Nodes.Add(rootNode);

            return(scaffoldModel);
        }
        /// <summary>
        /// Add a root node to the scaffold model. The extensions allows the calling code to pass in
        /// Root Nodes with or without an Id or Name and provide the Id and Name implicitly via the extension
        /// function
        /// </summary>
        /// <param name="scaffoldModel">The extended scaffold model</param>
        /// <param name="rootNode">The actual roote node beeing added to the scaffold model</param>
        public static FilterScaffoldModel <T> AddRootNodeToBaseLevel <T>(this FilterScaffoldModel <T> scaffoldModel, FilterRootNode rootNode)
        {
            scaffoldModel.FilterNodes.Add(rootNode);

            return(scaffoldModel);
        }