private HtmlNodeElement GetFormButtons() { HtmlSelfClosingTagElement submit = new HtmlSelfClosingTagElement("input"); submit.AddAttribute(new HtmlTypeAttribute("submit")); HtmlSelfClosingTagElement reset = new HtmlSelfClosingTagElement("input"); reset.AddAttribute(new HtmlTypeAttribute("reset")); if (_options.SubmitButtonAttributes != null) { submit.AddRangeAttributes(_options.SubmitButtonAttributes); } if (_options.ResetButtonAttributes != null) { reset.AddRangeAttributes(_options.ResetButtonAttributes); } HtmlNodeElement wrapper = new HtmlNodeElement("span"); wrapper.Append(submit); wrapper.Append(reset); return(wrapper); }
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 IHtmlElement GetInput(string type, string name, object value, List <SelectListItem> values, string format = null) { IHtmlElement input = new HtmlSelfClosingTagElement("input"); input.AddAttribute(new HtmlNameAttribute(name)); if (_options.InputAttributes != null) { input.AddRangeAttributes(_options.InputAttributes); } switch (type) { case "checkbox": input.AddAttributeValue("type", "checkbox"); input.AddAttributeValue("value", "true"); if (value != null && (bool)value == true) { input.AddAttribute(new HtmlAttribute("checked")); } break; case "color": input.AddAttributeValue("type", "color"); input.AddAttributeValue("value", value != null ? value.ToString() : ""); break; case "date": input.AddAttributeValue("type", "date"); input.AddAttributeValue("value", value != null ? ((DateTime)value).ToString(format) : ""); input.AddAttributeValue("data-format", format); break; case "datetime-local": input.AddAttributeValue("type", "datetime-local"); input.AddAttributeValue("value", value != null ? ((DateTime)value).ToString(format) : ""); input.AddAttributeValue("data-format", format); break; case "email": input.AddAttributeValue("type", "email"); input.AddAttributeValue("value", value != null ? value.ToString() : ""); break; case "file": input.AddAttributeValue("type", "file"); break; case "hidden": input.AddAttributeValue("type", "hidden"); input.AddAttributeValue("value", value != null ? value.ToString() : ""); break; case "month": input.AddAttributeValue("type", "month"); input.AddAttributeValue("value", value != null ? value.ToString() : ""); input.AddAttributeValue("data-format", format); break; case "number": input.AddAttributeValue("type", "number"); input.AddAttributeValue("value", value != null ? value.ToString() : ""); break; case "password": input.AddAttributeValue("type", "password"); input.AddAttributeValue("value", value != null ? value.ToString() : ""); break; case "radio": input = GeRadioButtonsGroup(name, values, value != null ? value.ToString() : ""); break; case "range": input.AddAttributeValue("type", "range"); input.AddAttributeValue("value", value != null ? value.ToString() : ""); break; case "search": input.AddAttributeValue("type", "search"); input.AddAttributeValue("value", value != null ? value.ToString() : ""); break; case "tel": input.AddAttributeValue("type", "tel"); input.AddAttributeValue("value", value != null ? value.ToString() : ""); break; case "time": input.AddAttributeValue("type", "time"); input.AddAttributeValue("value", value != null ? value.ToString() : ""); break; case "url": input.AddAttributeValue("type", "url"); input.AddAttributeValue("value", value != null ? value.ToString() : ""); break; default: input.AddAttributeValue("type", "text"); input.AddAttributeValue("value", value != null ? value.ToString() : ""); break; } return(input); }
/// <summary> /// Create html content. /// </summary> /// <param name="htmlElement">Object of type HtmlSelfClosingTagElement, for convert to standart HTML self closing tag content.</param> /// <returns>Html content repsresent specified self closing tag element.</returns> public IHtmlContent CreateHtmlContent(HtmlSelfClosingTagElement htmlElement) { return(new HtmlString( $"{CreateStartTag(htmlElement.TagName)}" .Insert((htmlElement.TagName.Length + 1), htmlElement.Attributes.IsNullOrEmpty() ? "" : $" {String.Join(" ", htmlElement.Attributes.Select(x => CreateAtribute(x)))}"))); }