public static HtmlHelper RadioGroup(this HtmlHelper htmlHelper, string exp, RadioGroupSettings settings = null) { htmlHelper.ResetBuilderWithCheck("DIV", "rgp", exp); htmlHelper.AddClass("radio-group"); htmlHelper.AddStyle("width", "160px"); htmlHelper.Builder.SetInnerHtml(BuildRadioOptions(exp, settings)); return(htmlHelper); }
private static string BuildRadioOptions(string name, Type enumType, RadioGroupSettings settings) { var width = settings == null || settings.ItemWidth == null ? string.Empty : "width: " + settings.ItemWidth + "px;"; var sb = new StringBuilder(); foreach (var kvp in enumType.GetEnumList()) { var chk = settings != null && settings.Value != null && settings.Value.To <int>() == kvp.Key ? " checked=\"checked\"" : string.Empty; sb.AppendFormat("<div style=\"float:left;{4}\"><input type=\"radio\" id=\"{3}_{0}_{1}\" name=\"{3}\" value=\"{1}\"{5} /><label for=\"{3}_{0}_{1}\">{2}</label></div>", enumType.Name, kvp.Key, kvp.Value, name, width, chk); } return(sb.ToString()); }
public static HtmlHelper <TModel> RadioGroup <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, Type enumType, RadioGroupSettings settings = null) { var metadata = new ModelPropertyBinder(expression); var propertyName = metadata.PropertyName; htmlHelper.ResetBuilder("DIV", "rgp" + propertyName, propertyName); htmlHelper.AddClass("radio-group"); htmlHelper.AddStyle("width", "160px"); htmlHelper.Builder.SetInnerHtml(BuildRadioOptions(propertyName, enumType, settings)); return(htmlHelper); }