I am trying to create a dynamic checkboxlist control with an extended html helper? The radio button list will be filled by a list of items? Not sure how to make this more flexible for any list items.
public static string CheckBoxList(this HtmlHelper helper, string name, <Some List> items)
{
var output = new StringBuilder();
output.Append(@"<div class=""checkboxList"">");
foreach (var item in items)
{
output.Append(@"<input type=""checkbox"" name=""");
output.Append(name);
output.Append("\" value=\"");
output.Append(item.Value);
output.Append("\"");
output.Append(" />");
output.Append(item.Value);
output.Append("<br />");
}
output.Append("</div>");
return output.ToString();
}
How about passing in the value property name as a parameter and then getting that property with reflection?
So your method Signature is like so: