/ Published in: C#
Code snippet that allows developers to use a generic radiobuttonlist in the MVC Framework
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
public static void ShowCheckBoxList<T>(this ViewPage page, IList<string> list, string name, Expression<Func<T, object>> valueProperty, Expression<Func<T, object>> displayProperty, List<string> selectedValue, System.Web.UI.WebControls.Orientation orientation) { if (writer != null) { for (int i = 0; i < list.Count; i++) { string value = list[i]; writer.AddAttribute(HtmlTextWriterAttribute.Type, "CHECKBOX"); writer.AddAttribute(HtmlTextWriterAttribute.Id, name + "_" + i); writer.AddAttribute(HtmlTextWriterAttribute.Name, name, true); writer.AddAttribute(HtmlTextWriterAttribute.Value, value, true); if (selectedValue != null &&selectedValue.Contains(value)) writer.RenderBeginTag(HtmlTextWriterTag.Input); writer.Write(value); writer.RenderEndTag(); if (orientation == System.Web.UI.WebControls.Orientation.Vertical) { writer.Write("<br/>"); } } } }