using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Linq.Expressions; using Bowin.Web.Controls.Mvc; namespace EMIS.Web.Controls { public static class MinOrEqualDropDownListExtensions { public static MvcHtmlString MinOrEqualDropDownListFor(this HtmlHelper htmlHelper, Expression> expression, DropdownListOptions dropdownListOptions = null, System.Collections.Generic.IDictionary htmlAttributes = null) { ModelMetadata modelMetadata = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData); string fullHtmlFieldName = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(ExpressionHelper.GetExpressionText(expression)); //MVC验证支持 var validateAttributes = htmlHelper.GetUnobtrusiveValidationAttributes(fullHtmlFieldName, modelMetadata); if (htmlAttributes == null) { htmlAttributes = new Dictionary(); } validateAttributes.ToList().ForEach(x => htmlAttributes.Add(x.Key, x.Value.ToString())); if (dropdownListOptions == null) dropdownListOptions = new DropdownListOptions(); dropdownListOptions.ItemList = new List { new DropdownListItem { Text = "<", Value = "<" }, new DropdownListItem { Text = "<=", Value = "<=" } }; if (string.IsNullOrEmpty(dropdownListOptions.ID)) { dropdownListOptions.ID = fullHtmlFieldName; } dropdownListOptions.Name = fullHtmlFieldName; dropdownListOptions.SelectedValue = (modelMetadata.Model ?? "<"); return htmlHelper.DropdownList(dropdownListOptions, htmlAttributes); } } }