using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using Bowin.Web.Controls.Mvc; namespace EMIS.Web.Controls { public static class NumberRangeDropdownListExtensions { public static MvcHtmlString NumberRangeDropdownList(this HtmlHelper htmlHelper, int minValue, int maxValue, DropdownListOptions dropdownListOptions = null, System.Collections.Generic.IDictionary htmlAttributes = null) { if (dropdownListOptions == null) dropdownListOptions = new DropdownListOptions(); List valueList = new List(); for (int i = minValue; i <= maxValue; i ++) { valueList.Add(i); } dropdownListOptions.ItemList = valueList.Select(x => new DropdownListItem { Text = x.ToString(), Value = x.ToString() }).ToList(); if (dropdownListOptions.SelectedValue == null) { dropdownListOptions.SelectedValue = DropdownList.PLEASE_SELECT.ToString(); } return htmlHelper.DropdownList(dropdownListOptions, htmlAttributes); } } }