示例#1
0
        public FormContainer(HtmlTextWriter htmlTextWriter,
                             string url,
                             BootstrapFormType formType = BootstrapFormType.Horizontal,
                             FormMethod method          = FormMethod.Post,
                             object htmlAttributes      = null)
        {
            this.textWriter = htmlTextWriter;
            this.formType   = formType;

            textWriter.AddAttribute("method", method.ToString());

            textWriter.AddAttribute("action", url);
            var htmlAttributesCollection = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);

            switch (this.formType)
            {
            case BootstrapFormType.Horizontal: htmlAttributesCollection.Merge("class", "form-horizontal"); break;

            case BootstrapFormType.Vertical: htmlAttributesCollection.Merge("class", "form-vertical"); break;

            case BootstrapFormType.Inline: htmlAttributesCollection.Merge("class", "form-inline"); break;
            }

            foreach (var htmlAttribute in htmlAttributesCollection)
            {
                textWriter.AddAttribute(htmlAttribute.Key, htmlAttribute.Value.ToString());
            }
            textWriter.RenderBeginTag(HtmlTextWriterTag.Form);
        }
示例#2
0
        public FormContainer(HtmlTextWriter htmlTextWriter,
            string url ,
            BootstrapFormType formType = BootstrapFormType.Horizontal,
            FormMethod method = FormMethod.Post,
            object htmlAttributes = null)
        {
            this.textWriter = htmlTextWriter;
            this.formType = formType;

           // textWriter.AddAttribute("method", method.ToString());

            //textWriter.AddAttribute("action", url ) ;
            var htmlAttributesCollection = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);

            switch (this.formType)
            {
                case BootstrapFormType.Horizontal: htmlAttributesCollection.Merge("class", "form-horizontal"); break;
                case BootstrapFormType.Vertical: htmlAttributesCollection.Merge("class", "form-vertical"); break;
                case BootstrapFormType.Inline: htmlAttributesCollection.Merge("class", "form-inline"); break;
            }

            foreach (var htmlAttribute in htmlAttributesCollection)
            {
                textWriter.AddAttribute(htmlAttribute.Key, htmlAttribute.Value.ToString());
            }
            textWriter.RenderBeginTag(HtmlTextWriterTag.Form);
            
        }
示例#3
0
        public BootstrapFormBuilder <TModel> BeginForm(BootstrapFormType formType)
        {
            string rawUrl = this.helper.ViewContext.HttpContext.Request.RawUrl;

            return(new BootstrapFormBuilder <TModel>(
                       this.helper, new BootstrapForm(formType, rawUrl, FormMethod.Post, new RouteValueDictionary())));
        }
示例#4
0
        public BootstrapFormBuilder <TModel> BeginForm(BootstrapFormType formType, IDictionary <string, object> htmlAttributes)
        {
            string rawUrl = this.helper.ViewContext.HttpContext.Request.RawUrl;

            return(new BootstrapFormBuilder <TModel>(
                       this.helper, new BootstrapForm(formType, rawUrl, FormMethod.Post, htmlAttributes)));
        }
示例#5
0
        public BootstrapFormBuilder <TModel> BeginForm(BootstrapFormType formType, object htmlAttributes)
        {
            string rawUrl = _helper.ViewContext.HttpContext.Request.RawUrl;

            return(new BootstrapFormBuilder <TModel>(
                       _helper, new BootstrapForm(formType, rawUrl, FormMethod.Post, new RouteValueDictionary(htmlAttributes))));
        }
示例#6
0
        public FormContainer BeginForm(BootstrapFormType formType)
        {
            var rawUrl     = this.helper.ViewContext.HttpContext.Request.RawUrl;
            var textWriter = new HtmlTextWriter(helper.ViewContext.Writer);
            var fc         = new FormContainer(textWriter, rawUrl);

            return(fc);
        }
        public MvcHtmlString BuildForm(BootstrapFormType formType, List<FormElement> formElements)
        {
            var formBuilderParameters = new BuilderParameters(formType);

            var formMarkUp = this.formBuilder.BuildForm(formElements, formBuilderParameters);

            return new MvcHtmlString(formMarkUp);
        }
示例#8
0
        public FormContainer BeginForm(BootstrapFormType formType, object htmlAttributes)
        {
            var rawUrl     = this.helper.ViewContext.HttpContext.Request.RawUrl;
            var textWriter = new HtmlTextWriter(helper.ViewContext.Writer);
            var fc         = new FormContainer(textWriter, rawUrl, method: FormMethod.Post, htmlAttributes: htmlAttributes);

            return(fc);
        }
        public MvcHtmlString BuildForm(BootstrapFormType formType, List <FormElement> formElements)
        {
            var formBuilderParameters = new BuilderParameters(formType);

            var formMarkUp = this.formBuilder.BuildForm(formElements, formBuilderParameters);

            return(new MvcHtmlString(formMarkUp));
        }
示例#10
0
        public static MvcHtmlString DynamicForm <TModel>
            (this HtmlHelper <TModel> htmlHelper, BootstrapFormType formType = BootstrapFormType.Horizontal)
        {
            TModel model    = htmlHelper.ViewData.Model;
            var    elements = new FormElementsProvider <TModel>().ExtractElementsFromModel(model, htmlHelper);

            return(new BootStrapUIBuilder(Mode.Edit).BuildForm(formType, elements));
        }
示例#11
0
        public MvcHtmlString BuildElement(BootstrapFormType formType, FormElement formElement)
        {
            var sb = new StringBuilder();
            var formBuilderParameters = new BuilderParameters(formType);

            sb.Append(this.formBuilder.RenderElement(formElement, formBuilderParameters));

            return(new MvcHtmlString(sb.ToString()));
        }
示例#12
0
        public MvcHtmlString BuildForm(BootstrapFormType formType, List<FormElement> formElements)
        {
            var sb = new StringBuilder();
            var formBuilderParameters = new BuilderParameters(formType);

            sb.Append(this.formBuilder.BuildForm(formElements, formBuilderParameters));

            return new MvcHtmlString(sb.ToString());
        }
示例#13
0
        public MvcHtmlString BuildElement(BootstrapFormType formType, FormElement formElement)
        {
            var sb = new StringBuilder();
            var formBuilderParameters = new BuilderParameters(formType);

            sb.Append(this.formBuilder.RenderElement(formElement, formBuilderParameters));

            return new MvcHtmlString(sb.ToString());
        }
示例#14
0
        public MvcHtmlString BuildForm(BootstrapFormType formType, List <FormElement> formElements)
        {
            var sb = new StringBuilder();
            var formBuilderParameters = new BuilderParameters(formType);

            sb.Append(this.formBuilder.BuildForm(formElements, formBuilderParameters));

            return(new MvcHtmlString(sb.ToString()));
        }
示例#15
0
 public static void Begin(HtmlTextWriter htmlTextWriter, BootstrapFormType formType = BootstrapFormType.Horizontal)
 {
     var textWriter = htmlTextWriter;
     if (formType == BootstrapFormType.Horizontal)
     {
         // Controls Div
         textWriter.AddAttribute(HtmlTextWriterAttribute.Class, "col-lg-9");
     }
     
     textWriter.RenderBeginTag(HtmlTextWriterTag.Div);
     
 }
示例#16
0
        public static void Begin(HtmlTextWriter htmlTextWriter, BootstrapFormType formType = BootstrapFormType.Horizontal)
        {
            var textWriter = htmlTextWriter;

            if (formType == BootstrapFormType.Horizontal)
            {
                // Controls Div
                textWriter.AddAttribute(HtmlTextWriterAttribute.Class, "col-lg-9");
            }

            textWriter.RenderBeginTag(HtmlTextWriterTag.Div);
        }
示例#17
0
        public BootstrapForm(BootstrapFormType formType, string formAction, FormMethod method, IDictionary<string, object> htmlAttributes)
            : base("form", htmlAttributes)
        {
            this.FormType = formType;

            EnsureHtmlAttribute("action", formAction);
            EnsureHtmlAttribute("method", HtmlHelper.GetFormMethodString(method), true);

            switch (this.FormType)
            {
                case BootstrapFormType.Horizontal: EnsureClass("form-horizontal"); break;
                case BootstrapFormType.Vertical: EnsureClass("form-vertical"); break;
                case BootstrapFormType.Inline: EnsureClass("form-inline"); break;
                case BootstrapFormType.Search: EnsureClass("form-search"); break;
            }
        }
        public virtual MvcHtmlString Build(TModel model, BootstrapFormType formType, bool renderButtons = true)
        {
            var  sb               = new StringBuilder(2000);
            var  formElements     = ExtractElementsToRender(model);
            var  groupsofElements = formElements.OrderBy(x => x.ControlSpecs.GroupName).GroupBy(x => x.ControlSpecs.GroupName);
            bool useLegend        = (formElements.Select(x => x.ControlSpecs.GroupName).Distinct().Count() > 1);

            var stringWriter = new StringWriter(sb);

            using (var textWriter = new NavHtmlTextWritter(stringWriter))
            {
                RenderHiddenFields(model, formElements, textWriter);

                foreach (var groupedElements in groupsofElements)
                {
                    var groupName = (!String.IsNullOrEmpty(groupedElements.Key)) ? groupedElements.Key : "General";

                    using (new ElementGroup(textWriter, groupName, useLegend))
                    {
                        var elementsToRender = groupedElements.Where(x => x.ControlSpecs.Control != ControlType.Hidden)
                                               .OrderBy(x => x.ControlSpecs.Order);

                        // loop over the attributes (ordered)..
                        foreach (var formElement in elementsToRender)
                        {
                            using (new ControlGroup(textWriter))
                            {
                                ControlGroup.RenderLabel(formType, formElement, textWriter);

                                using (new ControlContainer(textWriter))
                                {
                                    // Control
                                    RenderElement(textWriter, model, formElement);
                                }
                            }
                        }
                    }
                }

                if (renderButtons)
                {
                    RenderButtons(textWriter);
                }

                return(new MvcHtmlString(sb.ToString()));
            }
        }
示例#19
0
        public BootstrapForm(BootstrapFormType formType, string formAction, FormMethod method, IDictionary <string, object> htmlAttributes)
            : base("form", htmlAttributes)
        {
            this.FormType = formType;

            EnsureHtmlAttribute("action", formAction);
            EnsureHtmlAttribute("method", HtmlHelper.GetFormMethodString(method), true);

            switch (this.FormType)
            {
            case BootstrapFormType.Horizontal: EnsureClass("form-horizontal"); break;

            case BootstrapFormType.Vertical: EnsureClass("form-vertical"); break;

            case BootstrapFormType.Inline: EnsureClass("form-inline"); break;

            case BootstrapFormType.Search: EnsureClass("form-search"); break;
            }
        }
示例#20
0
 public BootstrapFormBuilder <TModel> BeginRouteForm(string routeName, RouteValueDictionary routeValues, FormMethod method, BootstrapFormType formType = BootstrapFormType.Horizontal)
 {
     return(BeginRouteForm(routeName, routeValues, method, new RouteValueDictionary(), formType));
 }
示例#21
0
 public BootstrapFormBuilder <TModel> BeginRouteForm(string routeName, FormMethod method, IDictionary <string, object> htmlAttributes, BootstrapFormType formType = BootstrapFormType.Horizontal)
 {
     return(BeginRouteForm(routeName, new RouteValueDictionary(), method, htmlAttributes, formType));
 }
示例#22
0
 public BootstrapFormBuilder <TModel> BeginRouteForm(string routeName, object routeValues, BootstrapFormType formType = BootstrapFormType.Horizontal)
 {
     return(BeginRouteForm(routeName, new RouteValueDictionary(routeValues), FormMethod.Post, new RouteValueDictionary(), formType));
 }
示例#23
0
 public BootstrapFormBuilder <TModel> BeginRouteForm(RouteValueDictionary routeValues, BootstrapFormType formType = BootstrapFormType.Horizontal)
 {
     return(BeginRouteForm(null, routeValues, FormMethod.Post, new RouteValueDictionary(), formType));
 }
示例#24
0
 public BootstrapFormBuilder <TModel> BeginForm(string actionName, string controllerName, RouteValueDictionary routeValues, FormMethod method, BootstrapFormType formType = BootstrapFormType.Horizontal)
 {
     return(BeginForm(actionName, controllerName, routeValues, method, new RouteValueDictionary(), formType));
 }
示例#25
0
        public BootstrapFormBuilder <TModel> BeginForm(string actionName, string controllerName, RouteValueDictionary routeValues, FormMethod method, IDictionary <string, object> htmlAttributes, BootstrapFormType formType = BootstrapFormType.Horizontal)
        {
            string formAction = UrlHelper.GenerateUrl(null, actionName, controllerName, routeValues, _helper.RouteCollection, _helper.ViewContext.RequestContext, true);

            return(new BootstrapFormBuilder <TModel>(
                       _helper, new BootstrapForm(formType, formAction, method, htmlAttributes)));
        }
示例#26
0
 public BuilderParameters(BootstrapFormType formType)
 {
     this.formType = formType;
 }
示例#27
0
 public BootstrapFormBuilder <TModel> BeginRouteForm(string routeName, object routeValues, FormMethod method, object htmlAttributes, BootstrapFormType formType = BootstrapFormType.Horizontal)
 {
     return(BeginRouteForm(routeName, new RouteValueDictionary(routeValues), method, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes), formType));
 }
示例#28
0
        public FormContainer BeginForm(string actionName, string controllerName, RouteValueDictionary routeValues, FormMethod method, object htmlAttributes, BootstrapFormType formType = BootstrapFormType.Horizontal)
        {
            var formAction = UrlHelper.GenerateUrl(null, actionName, controllerName, routeValues, this.helper.RouteCollection, this.helper.ViewContext.RequestContext, true);
            var textWriter = new HtmlTextWriter(helper.ViewContext.Writer);
            var fc         = new FormContainer(textWriter, formAction, method: method, htmlAttributes: htmlAttributes, formType: formType);

            return(fc);
        }
示例#29
0
 public BuilderParameters(BootstrapFormType formType)
 {
     this.formType = formType;
 }
示例#30
0
        public BootstrapFormBuilder <TModel> BeginRouteForm(string routeName, RouteValueDictionary routeValues, FormMethod method, IDictionary <string, object> htmlAttributes, BootstrapFormType formType = BootstrapFormType.Horizontal)
        {
            string formAction = UrlHelper.GenerateUrl(routeName, null, null, routeValues, this.helper.RouteCollection, this.helper.ViewContext.RequestContext, false);

            return(new BootstrapFormBuilder <TModel>(
                       this.helper, new BootstrapForm(formType, formAction, method, htmlAttributes)));
        }
示例#31
0
        public static MvcHtmlString DynamicViewElement <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper,
                                                                           Expression <Func <TModel, TProperty> > expression, BootstrapFormType formType = BootstrapFormType.Horizontal)
        {
            TModel model = htmlHelper.ViewData.Model;

            var expressionText = ExpressionHelper.GetExpressionText(expression);

            var element = new FormElementsProvider <TModel>().ExtractSingleElementFromModel(model, htmlHelper, expressionText);

            return(new BootStrapUIBuilder(Mode.View).BuildElement(formType, element));
        }
示例#32
0
 public MvcHtmlString RenderUI(IDynamicUiBuilder <TModel> builder, BootstrapFormType formType, bool renderButtons = true)
 {
     return(builder.Build(helper.ViewData.Model, formType, renderButtons, helper));
 }
示例#33
0
 public FormContainer BeginForm(string actionName, string controllerName, RouteValueDictionary routeValues, BootstrapFormType formType = BootstrapFormType.Horizontal)
 {
     return(BeginForm(actionName, controllerName, routeValues, FormMethod.Post, new RouteValueDictionary(), formType));
 }
示例#34
0
 public static MvcHtmlString DynamicView <TModel>(this HtmlHelper <TModel> htmlHelper, List <FormElement> elements, BootstrapFormType formType = BootstrapFormType.Horizontal)
 {
     return(new BootStrapUIBuilder(Mode.View).BuildForm(formType, elements));
 }
示例#35
0
 public MvcHtmlString DynamicView(BootstrapFormType formType = BootstrapFormType.Horizontal)
 {
     return(RenderUI(GetViewBuilder(helper), formType, false));
 }
示例#36
0
 public FormContainer BeginForm(string actionName, string controllerName, FormMethod method, object htmlAttributes, BootstrapFormType formType = BootstrapFormType.Horizontal)
 {
     return(BeginForm(actionName, controllerName, new RouteValueDictionary(), method, htmlAttributes, formType));
 }
示例#37
0
 public MvcHtmlString DynamicForm(BootstrapFormType formType = BootstrapFormType.Horizontal)
 {
     return(RenderUI(GetFormBuilder(), formType));
 }