using System; using System.Collections.Generic; using System.Web.Mvc; using System.Web.Mvc.Html; using System.Web.Routing; namespace CustomHelperMethod { public static class HelperMethod { public static MvcHtmlString CustomGenderDropDownList(this HtmlHelper helper, string controlName, string optionalLabel = "", object htmlAttributes = null) { IEnumerable<SelectListItem> selectList = null; List<SelectListItem> genderList = new List<SelectListItem>(); genderList.Add(new SelectListItem() { Text = "Male", Value = "1" }); genderList.Add(new SelectListItem() { Text = "Female", Value = "2" }); selectList = (IEnumerable<SelectListItem>)new SelectList(genderList, "Value", "Text"); if (htmlAttributes != null && htmlAttributes is RouteValueDictionary) { RouteValueDictionary htmlAttr = htmlAttributes as RouteValueDictionary; if (!string.IsNullOrEmpty(optionalLabel)) return helper.DropDownList(controlName, selectList, optionalLabel, htmlAttr); else return helper.DropDownList(controlName, selectList, htmlAttr); } if (!string.IsNullOrEmpty(optionalLabel)) return helper.DropDownList(controlName, selectList, optionalLabel, htmlAttributes); else return helper.DropDownList(controlName, selectList, htmlAttributes); } } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter