1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- 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<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper,
- Expression<Func<TModel, TProperty>> expression,
- DropdownListOptions dropdownListOptions = null,
- System.Collections.Generic.IDictionary<string, string> htmlAttributes = null)
- {
- ModelMetadata modelMetadata = ModelMetadata.FromLambdaExpression<TModel, TProperty>(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<string, string>();
- }
- validateAttributes.ToList().ForEach(x => htmlAttributes.Add(x.Key, x.Value.ToString()));
- if (dropdownListOptions == null)
- dropdownListOptions = new DropdownListOptions();
- dropdownListOptions.ItemList = new List<DropdownListItem>
- {
- 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);
- }
- }
- }
|