internal HtmlNodeElement GenerateFormElement()
        {
            HtmlNodeElement formContent = new HtmlNodeElement("div");

            formContent.Children = GetHtmlFormGroups();

            HtmlNodeElement formFooter = new HtmlNodeElement("div");

            formFooter.Append(GetFormButtons());

            if (_options.FormFooterAttributes != null)
            {
                formFooter.AddRangeAttributes(_options.FormFooterAttributes);
            }

            if (_options != null && _options.FormFooterTemplateFunc != null)
            {
                formFooter = _options.FormFooterTemplateFunc(formFooter);
            }

            HtmlNodeElement form = new HtmlNodeElement("form");

            form.AddAttributeValue("action", _options.Action);
            form.Attributes = _options?.FormAttributes;
            form.Append(formContent);
            form.Append(formFooter);

            return(form);
        }
        private HtmlNodeElement GetLabel(PropertyInfo propInfo)
        {
            DisplayAttribute displayAttr = propInfo.GetCustomAttribute <DisplayAttribute>();
            bool             IsRequired  = propInfo.GetCustomAttribute <RequiredAttribute>() != null;
            string           labelText   = $"{(displayAttr != null ? displayAttr.Name : propInfo.Name)}{(IsRequired ? "*" : "")}:";

            if (_options != null && _options.LabelTemplate != null)
            {
                labelText = String.Format(_options.LabelTemplate, labelText);
            }
            else if (_options != null && _options.LabelTemplateFunc != null)
            {
                labelText = _options.LabelTemplateFunc(labelText);
            }

            HtmlNodeElement label = new HtmlNodeElement("label", labelText);

            label.Attributes = new IHtmlAttribute[] { new HtmlAttribute("for", propInfo.Name) };

            if (_options.LabelAttributes != null)
            {
                label.AddRangeAttributes(_options.LabelAttributes);
            }

            return(label);
        }
        private HtmlNodeElement GeRadioButtonsGroup(string name, IEnumerable <SelectListItem> values, string value, bool isMultiple = false)
        {
            HtmlNodeElement wrapper = new HtmlNodeElement("div");

            if (_options.RadioButtonsWrapperAttributes != null)
            {
                wrapper.AddRangeAttributes(_options.RadioButtonsWrapperAttributes);
            }

            foreach (var item in values)
            {
                HtmlNodeElement label = new HtmlNodeElement("label");
                label.Text(item.Text);

                if (_options.RadioButtonsGroupLabelAttributes != null)
                {
                    label.AddRangeAttributes(_options.RadioButtonsGroupLabelAttributes);
                }

                var radioInput = new HtmlSelfClosingTagElement("input")
                {
                    Attributes = new IHtmlAttribute[]
                    {
                        new HtmlAttribute("name", name),
                        new HtmlAttribute("value", item.Value),
                        new HtmlAttribute("type", isMultiple ? "checkbox" : "radio")
                    }
                };

                if (_options.RadioButtonsGroupInputAttributes != null)
                {
                    radioInput.AddRangeAttributes(_options.RadioButtonsGroupInputAttributes);
                }

                if (item.Selected || (value != null && item.Value == value.ToString()))
                {
                    radioInput.AddAttribute(new HtmlAttribute("checked"));
                }

                label.Append(radioInput);

                var div = new HtmlNodeElement("div");
                div.Append(label);

                if (_options.RadioButtonsGroupWrapperAttributes != null)
                {
                    div.AddRangeAttributes(_options.RadioButtonsGroupWrapperAttributes);
                }

                wrapper.Append(div);
            }

            return(wrapper);
        }
        private HtmlPairTagsElement GetFormGroup(PropertyInfo propInfo)
        {
            IHtmlElement    input        = GetProperInput(propInfo);
            HtmlNodeElement inputWrapper = new HtmlNodeElement("div");

            if (propInfo.GetCustomAttribute <HtmlInputAttribute>() != null)
            {
                input.AddAttribute(propInfo.GetCustomAttribute <HtmlInputAttribute>().Name);
            }

            inputWrapper.Append(input);
            // TODO Add validation element

            if (_options.InputWrapperAttributes != null)
            {
                inputWrapper.AddRangeAttributes(_options.InputWrapperAttributes);
            }

            HtmlNodeElement label = GetLabel(propInfo);

            HtmlNodeElement formGroup = new HtmlNodeElement("div");

            formGroup.Append(label);

            if (_options.FormGroupAttributes != null)
            {
                formGroup.AddRangeAttributes(_options.FormGroupAttributes);
            }

            formGroup.Append(inputWrapper);

            if (_options.FormGroupTemplateFunc != null)
            {
                formGroup = _options.FormGroupTemplateFunc(formGroup);
            }

            return(formGroup);
        }
        private HtmlNodeElement GetSelect(string name, IEnumerable <SelectListItem> values, string value, bool isMultiple = false)
        {
            HtmlNodeElement select = new HtmlNodeElement("select");

            select.AddAttribute(new HtmlNameAttribute(name));
            if (isMultiple)
            {
                select.AddAttribute("multiple");
            }

            if (_options.InputAttributes != null)
            {
                select.AddRangeAttributes(_options.InputAttributes);
            }

            foreach (var item in values)
            {
                var option = new HtmlPairTagsElement("option")
                {
                    Attributes = new IHtmlAttribute[]
                    {
                        new HtmlAttribute("value", item.Value)
                    }
                };

                option.Text(new HtmlString(item.Text));

                if (item.Selected || (value != null && item.Value == value.ToString()))
                {
                    option.AddAttribute("selected");
                }

                select.Append(option);
            }

            return(select);
        }