public static string RenderInputListFromEnum(HtmlHelper html, BootstrapInputListFromEnumModel model) { Type t = model.metadata.ModelType; if (t.GetGenericTypeDefinition() == typeof(Nullable<>)) { t = t.GetGenericArguments().First(); } List<SelectListItem> listItems = new List<SelectListItem>(); foreach (var e in Enum.GetValues(t).OfType<Enum>()) { listItems.Add(new SelectListItem() { Text = e.GetEnumDescription(), Value = Enum.Parse(t, e.ToString()).ToString(), Selected = e.Equals(model.metadata.Model) }); } List<string> inputs = new List<string>(); int index = 0; foreach (var item in listItems) { inputs.Add(Renderer.RenderInputListItem( html, model.inputType, model.htmlFieldName, model.metadata, index, item.Value, item.Text, null, null, item.Selected, false)); index++; } return Renderer.RenderInputListContainer( html, model.htmlFieldName, inputs, model.numberOfColumns, model.displayInColumnsCondition, model.columnPixelWidth, model.displayInlineBlock, model.marginRightPx, model.displayValidationMessage, model.validationMessageStyle); }
public static string RenderControlGroupInputListFromEnum(HtmlHelper html, BootstrapInputListFromEnumModel model) { var input = Renderer.RenderInputListFromEnum(html, model); string label = Renderer.RenderLabel(html, new BootstrapLabelModel { htmlFieldName = model.htmlFieldName, metadata = model.metadata, htmlAttributes = new { @class = "control-label" }.ToDictionary() }); bool fieldIsValid = true; if(model != null) fieldIsValid = html.ViewData.ModelState.IsValidField(model.htmlFieldName); return new BootstrapControlGroup(input, label, ControlGroupType.textboxLike, fieldIsValid).ToHtmlString(); }