public static string RenderFormGroupRadioButton(HtmlHelper html, RadioButtonModel inputModel, LabelModel labelModel) { string validationMessage = ""; string radioType = "form-icon"; if (inputModel.displayValidationMessage) { string 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 = RenderControl.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() }); bool 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); string validationMessage = ""; if (model.displayValidationMessage) { string 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); }