Ejemplo n.º 1
0
        /// <summary>
        /// Uses the defined html conventions to display the view model
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="html"></param>
        /// <returns></returns>
        public static HtmlTag DisplayModel <T>(this HtmlHelper <T> html)
        {
            var dt   = html.ViewData.ModelMetadata;
            var info = new ModelInfo(dt, html.ViewContext);

            return(info.ConventionsRegistry().Displays.GenerateTags(info));
        }
Ejemplo n.º 2
0
        public static HtmlTag AddValidationMessage(HtmlTag tag, ModelInfo info)
        {
            if (tag.HasChild <ValidationMessageTag>())
            {
                return(tag);
            }
            var input = tag.FirstNonHiddenInput();

            if (input == null)
            {
                return(tag);
            }
            var validator = info.ConventionsRegistry().Validation.GenerateTags(info);
            //input.CreateValidationTag(info);
            var parent = input.Parent;
            var res    = tag;

            if (parent == null)
            {
                parent = HtmlTag.Placeholder();
                parent.Append(tag);
                res = parent;
            }
            var pos = input.PositionAsChild();

            validator.RegisterParent(parent);
            parent.Children.Insert(pos + 1, validator);
            return(res);
        }
Ejemplo n.º 3
0
        public static HtmlTag AddEditorLabel(HtmlTag tag, ModelInfo info)
        {
            if (tag.HasChild <LabelTag>())
            {
                return(tag);
            }
            var input = tag.FirstNonHiddenInput();

            if (input == null)
            {
                return(tag);
            }
            var label  = info.ConventionsRegistry().Labels.GenerateTags(info);
            var parent = input.Parent;
            var res    = tag;

            if (parent == null)
            {
                parent = HtmlTag.Placeholder();
                parent.Append(tag);
                res = parent;
            }
            var pos = input.PositionAsChild();

            if (pos == 0)
            {
                pos = 1;
            }
            label.RegisterParent(parent);
            parent.Children.Insert(pos - 1, label);
            return(res);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Uses the defined html conventions to build an editor widget for model
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="html"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        public static HtmlTag EditorWidget <T>(this HtmlHelper <T> html, object model)
        {
            model.MustNotBeNull();
            var metadata = ModelMetadataProviders.Current.GetMetadataForType(() => model, model.GetType());
            var info     = new ModelInfo(metadata, html.ViewContext);

            return(info.ConventionsRegistry().Editors.GenerateTags(info));
        }
 public static HtmlTag AddValidationMessage(HtmlTag tag, ModelInfo info)
 {
     if (tag.HasChild<ValidationMessageTag>()) return tag;
     var input = tag.FirstNonHiddenInput();
     if (input == null) return tag;
     var validator = info.ConventionsRegistry().Validation.GenerateTags(info);
         //input.CreateValidationTag(info);
     var parent = input.Parent;
     var res = tag;
     if (parent == null)
     {
         parent = HtmlTag.Placeholder();
         parent.Append(tag);
         res = parent;
     }
     var pos = input.PositionAsChild();
     validator.RegisterParent(parent);
     parent.Children.Insert(pos + 1, validator);
     return res;
 }
 public static HtmlTag AddEditorLabel(HtmlTag tag, ModelInfo info)
 {
     if (tag.HasChild<LabelTag>()) return tag;
     var input = tag.FirstNonHiddenInput();
     if (input == null) return tag;
     var label = info.ConventionsRegistry().Labels.GenerateTags(info);
     var parent = input.Parent;
    var res = tag;
     if (parent == null)
     {
         parent = HtmlTag.Placeholder();
         parent.Append(tag);
         res = parent;
     }
     var pos = input.PositionAsChild();
     if (pos == 0) pos = 1;
     label.RegisterParent(parent);
     parent.Children.Insert(pos - 1, label);
     return res;
 }