Ejemplo n.º 1
0
        public static string DynamicField(this HtmlHelper html, object entity, MetaColumn column, string uiHint, DataBoundControlMode mode)
        {
            var host = new SimpleFieldTemplateHost()
            {
                Column = column, Mode = mode
            };

            IFieldTemplate  fieldTemplate        = MetaModel.Default.FieldTemplateFactory.CreateFieldTemplate(column, mode, uiHint ?? column.UIHint);
            ViewUserControl fieldTemplateControl = fieldTemplate as ViewUserControl;

            if (fieldTemplateControl == null)
            {
                throw new InvalidOperationException("Cannot render a dynamic field whose field template is not a ViewUserControl");
            }

            fieldTemplate.SetHost(host);
            return(html.RenderViewUserControl(fieldTemplateControl, entity));
        }
        public override IFieldTemplate CreateFieldTemplate(MetaColumn column, DataBoundControlMode mode, string uiHint)
        {
            // Call Preprocess mode so that we do set the right mode base on the the column's attributes
            mode = PreprocessMode(column, mode);
            bool readOnly = (mode == DataBoundControlMode.ReadOnly);

            // If the folder doesn't exist use the fallback
            if (!DirectoryExists)
            {
                return(CreateFieldTemplate(readOnly, column));
            }

            // Always see check if the base found anything first then fall back to the simple field template
            IFieldTemplate fieldTemplate = base.CreateFieldTemplate(column, mode, uiHint);

            // If there was no field template found and the user specified a uiHint then use the default behavior
            if (!String.IsNullOrEmpty(uiHint))
            {
                return(fieldTemplate);
            }

            return(fieldTemplate ?? CreateFieldTemplate(readOnly, column));
        }