public static string RenderFormGroupRadioButton(HtmlHelper html, RadioButtonModel inputModel, LabelModel labelModel) { var validationMessage = ""; var radioType = "form-icon"; if (inputModel.displayValidationMessage) { var validation = html.ValidationMessage(inputModel.htmlFieldName).ToHtmlString(); validationMessage = new HelpText(validation, inputModel.validationMessageStyle).ToHtmlString(); } if (labelModel == null && inputModel.RadioType != InputRadioCheckBoxType._NotSet) radioType = inputModel.RadioType.ToName(); var label = RenderLabel(html, labelModel ?? new LabelModel { htmlFieldName = inputModel.htmlFieldName, metadata = inputModel.metadata, innerInputType = InputType.Radio, innerInputModel = inputModel, innerValidationMessage = validationMessage, htmlAttributes = new {@class = $"form-radio {radioType} form-text"}.ToDictionary() }); var fieldIsValid = true; if (inputModel != null) fieldIsValid = html.ViewData.ModelState.IsValidField(inputModel.htmlFieldName); return new FormGroup(null, label, FormGroupType.CheckBoxLike, fieldIsValid).ToHtmlString(); }
public static HtmlString RenderRadioButton(HtmlHelper html, RadioButtonModel model) { model.htmlAttributes.MergeHtmlAttributes(html.GetUnobtrusiveValidationAttributes(model.htmlFieldName, model.metadata)); if (!string.IsNullOrEmpty(model.id)) model.htmlAttributes.AddOrReplace("id", model.id); var validationMessage = ""; if (model.displayValidationMessage) { var validation = html.ValidationMessage(model.htmlFieldName).ToHtmlString(); validationMessage = new HelpText(validation, model.validationMessageStyle).ToHtmlString(); } return new HtmlString( html.RadioButton(model.htmlFieldName, model.value, model.isChecked, model.htmlAttributes.FormatHtmlAttributes()) .ToHtmlString() + validationMessage); }
public static string RenderInputListItem(HtmlHelper html, InputType inputType, string htmlFieldName, ModelMetadata metadata, int index, string inputValue, string inputText, object inputHtmlAttributes, object labelHtmlAttributes, bool inputIsChecked, bool inputIsDisabled, InputRadioCheckBoxType inputItemType) { var input = string.Empty; var fullHtmlFieldName = html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(htmlFieldName); var htmlAttrs = labelHtmlAttributes.ToDictionary(); var itemType = "form-icon"; if (inputItemType != InputRadioCheckBoxType._NotSet) itemType = inputItemType.ToName(); switch (inputType) { case InputType._NotSet: break; case InputType.CheckBoxList: { htmlAttrs.AddOrMergeCssClass("class", $"form-checkbox {itemType} form-text").FormatHtmlAttributes(); var checkboxModel = new CheckBoxModel { htmlFieldName = htmlFieldName, value = inputValue, metadata = metadata, htmlAttributes = inputHtmlAttributes.ToDictionary().FormatHtmlAttributes(), id = fullHtmlFieldName.FormatForMvcInputId() + "_" + index, isChecked = inputIsChecked, isDisabled = inputIsDisabled }; input = RenderCheckBoxCustom(html, checkboxModel).ToHtmlString(); break; } case InputType.RadioList: { htmlAttrs.AddOrMergeCssClass("class", $"form-radio {itemType} form-text").FormatHtmlAttributes(); var radiobuttonModel = new RadioButtonModel { htmlFieldName = htmlFieldName, value = inputValue, metadata = metadata, htmlAttributes = inputHtmlAttributes.ToDictionary().FormatHtmlAttributes(), id = fullHtmlFieldName.FormatForMvcInputId() + "_" + index, isChecked = inputIsChecked, isDisabled = inputIsDisabled }; input = RenderRadioButton(html, radiobuttonModel).ToHtmlString(); break; } default: break; } var labelModel = new LabelModel { index = index, htmlFieldName = htmlFieldName, labelText = inputText, metadata = metadata, htmlAttributes = htmlAttrs, innerInput = MvcHtmlString.Create(input), showRequiredStar = false }; var labeledInput = RenderLabel(html, labelModel).ToHtmlString(); return labeledInput; }