123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using System.Linq.Expressions;
- using Autofac;
- using Bowin.Web.Controls.Mvc;
- using EMIS.Utility;
- using EMIS.Entities;
- using EMIS.ViewModel;
- using EMIS.ViewModel.CacheManage;
- namespace EMIS.Web.Controls
- {
- public static class DictionaryDropDownListExtensions
- {
- /// <summary>
- /// 字典下拉菜单控件,下拉列出指定字典表中的枚举项
- /// </summary>
- /// <param name="htmlHelper"></param>
- /// <param name="dictionaryItem">指定要列出的字典类型</param>
- /// <param name="dropdownListOptions">下拉菜单控件配置项,除ItemSourceUrl、TextField、ValueField、ItemSource外其他都生效</param>
- /// <param name="htmlAttributes">自定义Html属性扩展,用Dictionary的方式定义,例如:new Dictionary<string, string> {
- /// { "style", "width: 100%;" }, { "name", "ddlUsers" }
- /// }
- /// </param>
- /// <returns></returns>
- public static MvcHtmlString DictionaryDropDownList(this HtmlHelper htmlHelper, DictionaryItem dictionaryItem, DropdownListOptions dropdownListOptions = null, System.Collections.Generic.IDictionary<string, string> htmlAttributes = null)
- {
- return DictionaryDropDownListSearch(htmlHelper, dictionaryItem.ToString(), dropdownListOptions, htmlAttributes);
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="htmlHelper"></param>
- /// <param name="dictionaryCode"></param>
- /// <param name="dropdownListOptions"></param>
- /// <param name="htmlAttributes"></param>
- /// <returns></returns>
- private static MvcHtmlString DictionaryDropDownListSearch(HtmlHelper htmlHelper, string dictionaryCode, DropdownListOptions dropdownListOptions, IDictionary<string, string> htmlAttributes = null)
- {
- if (dropdownListOptions == null)
- dropdownListOptions = new DropdownListOptions();
- dropdownListOptions.ItemSourceUrl = UrlHelper.GenerateContentUrl("~/Common/DictionaryDropDown?dictionaryCode="
- + dictionaryCode, htmlHelper.ViewContext.HttpContext);
- if (dropdownListOptions.SelectedValue == null)
- {
- dropdownListOptions.SelectedValue = DropdownList.PLEASE_SELECT.ToString();
- }
- return htmlHelper.DropdownList(dropdownListOptions, htmlAttributes);
- //return htmlHelper.ConvertToComboGrid(dictionaryCode, dropdownListOptions, htmlAttributes);
- }
- /// <summary>
- /// 字典下拉菜单控件,下拉列出指定字典表中的枚举项
- /// </summary>
- /// <param name="htmlHelper"></param>
- /// <param name="dictionaryItem">指定要列出的字典类型,用字符串表示</param>
- /// <param name="dropdownListOptions">下拉菜单控件配置项,除ItemSourceUrl、TextField、ValueField、ItemSource外其他都生效</param>
- /// <param name="htmlAttributes">自定义Html属性扩展,用Dictionary的方式定义,例如:new Dictionary<string, string> {
- /// { "style", "width: 100%;" }, { "name", "ddlUsers" }
- /// }
- /// </param>
- /// <returns></returns>
- public static MvcHtmlString DictionaryDropDownList(this HtmlHelper htmlHelper, string dictionaryItem, DropdownListOptions dropdownListOptions = null, System.Collections.Generic.IDictionary<string, string> htmlAttributes = null)
- {
- return DictionaryDropDownListSearch(htmlHelper, dictionaryItem, dropdownListOptions, htmlAttributes);
- }
- /// <summary>
- /// 绑定ViewModel的字典下拉菜单控件,下拉列出指定字典表中的枚举项
- /// </summary>
- /// <typeparam name="TModel"></typeparam>
- /// <typeparam name="TProperty"></typeparam>
- /// <param name="htmlHelper"></param>
- /// <param name="dictionaryItem">指定要列出的字典类型</param>
- /// <param name="expression">定义绑定属性的lamda,如:(x => x.LoginID)</param>
- /// <param name="dropdownListOptions">下拉菜单控件配置项,除ItemSourceUrl、TextField、ValueField、ItemSource外其他都生效</param>
- /// <param name="htmlAttributes">自定义Html属性扩展,用Dictionary的方式定义,例如:new Dictionary<string, string> {
- /// { "style", "width: 100%;" }, { "name", "ddlUsers" }
- /// }
- /// </param>
- /// <returns></returns>
- public static MvcHtmlString DictionaryDropDownListFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, DictionaryItem dictionaryItem,
- 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()));
- return DictionaryDropDownListForBind(htmlHelper, dictionaryItem.ToString(), modelMetadata, dropdownListOptions, htmlAttributes, fullHtmlFieldName);
- }
- /// <summary>
- /// 绑定ViewModel的字典下拉菜单控件,下拉列出指定字典表中的枚举项
- /// </summary>
- /// <typeparam name="TModel"></typeparam>
- /// <typeparam name="TProperty"></typeparam>
- /// <param name="htmlHelper"></param>
- /// <param name="dictionaryItemName">指定要列出的字典类型,用字符串表示</param>
- /// <param name="expression">定义绑定属性的lamda,如:(x => x.LoginID)</param>
- /// <param name="dropdownListOptions">下拉菜单控件配置项,除ItemSourceUrl、TextField、ValueField、ItemSource外其他都生效</param>
- /// <param name="htmlAttributes">自定义Html属性扩展,用Dictionary的方式定义,例如:new Dictionary<string, string> {
- /// { "style", "width: 100%;" }, { "name", "ddlUsers" }
- /// }
- /// </param>
- /// <returns></returns>
- public static MvcHtmlString DictionaryDropDownListFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, string dictionaryItemName,
- 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()));
- return DictionaryDropDownListForBind(htmlHelper, dictionaryItemName, modelMetadata, dropdownListOptions, htmlAttributes, fullHtmlFieldName);
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="htmlHelper"></param>
- /// <param name="dictionaryCode"></param>
- /// <param name="modelMetadata"></param>
- /// <param name="dropdownListOptions"></param>
- /// <param name="htmlAttributes"></param>
- /// <param name="fullHtmlFieldName"></param>
- /// <returns></returns>
- private static MvcHtmlString DictionaryDropDownListForBind(HtmlHelper htmlHelper, string dictionaryCode, ModelMetadata modelMetadata,
- DropdownListOptions dropdownListOptions, IDictionary<string, string> htmlAttributes, string fullHtmlFieldName)
- {
- if (dropdownListOptions == null)
- dropdownListOptions = new DropdownListOptions();
- dropdownListOptions.ItemSourceUrl = UrlHelper.GenerateContentUrl("~/Common/DictionaryDropDown?dictionaryCode="
- + dictionaryCode, htmlHelper.ViewContext.HttpContext);
- if (string.IsNullOrEmpty(dropdownListOptions.ID))
- {
- dropdownListOptions.ID = fullHtmlFieldName;
- }
- dropdownListOptions.Name = fullHtmlFieldName;
- dropdownListOptions.SelectedValue = Convert.ToString((int)(modelMetadata.Model ?? DropdownList.PLEASE_SELECT));
- return htmlHelper.DropdownList(dropdownListOptions, htmlAttributes);
- //return htmlHelper.ConvertToComboGrid(dictionaryCode, dropdownListOptions, htmlAttributes);
- }
- /// <summary>
- /// 专为查询使用的字典下拉菜单控件,下拉列出指定字典表中的枚举项,不推荐使用
- /// </summary>
- /// <param name="htmlHelper"></param>
- /// <param name="dictionaryItem">指定要列出的字典类型</param>
- /// <param name="dataGridID">查询影响的数据列表控件ID</param>
- /// <param name="dropdownListOptions">下拉菜单控件配置项,除ItemSourceUrl、TextField、ValueField、ItemSource外其他都生效</param>
- /// <param name="htmlAttributes">自定义Html属性扩展,用Dictionary的方式定义,例如:new Dictionary<string, string> {
- /// { "style", "width: 100%;" }, { "name", "ddlUsers" }
- /// }
- /// </param>
- /// <returns></returns>
- public static MvcHtmlString DictionaryDropDownListForSearch(this HtmlHelper htmlHelper, DictionaryItem dictionaryItem, string dataGridID,
- DropdownListOptions dropdownListOptions = null, System.Collections.Generic.IDictionary<string, string> htmlAttributes = null)
- {
- if (dropdownListOptions == null)
- {
- dropdownListOptions = new DropdownListOptions() { Name = dictionaryItem.ToString() };
- }
- dropdownListOptions.BindType = DropdownListBindType.SelectAll;
- if (htmlAttributes == null)
- {
- htmlAttributes = new Dictionary<string, string>();
- }
- htmlAttributes.Add("data-condition", dataGridID);
- return htmlHelper.DictionaryDropDownList(dictionaryItem, dropdownListOptions, htmlAttributes);
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="htmlHelper"></param>
- /// <param name="TypeID"></param>
- /// <param name="dictionaryCode"></param>
- /// <returns></returns>
- public static MvcHtmlString DictionaryItemName(this HtmlHelper htmlHelper, int? TypeID, string dictionaryCode)
- {
- string Name = string.Empty;
- if (TypeID == null)
- Name = "";
- using (var scop = AutofacHelper.Container.BeginLifetimeScope())
- {
- var DictionaryServices = scop.Resolve<EMIS.CommonLogic.SystemSetting.IDictionaryServices>();
- HttpRequest request = HttpContext.Current.Request;
- Name = IdNameExt.GetDictionaryItem(dictionaryCode)
- .Where(x => x.Value == TypeID)
- .Select(x => x.Name).FirstOrDefault();
- }
- return MvcHtmlString.Create(Name);
- }
- /// <summary>
- /// 学年数下拉控件,下拉列出学年数,如:2015、2016、2017等等……
- /// </summary>
- /// <param name="htmlHelper"></param>
- /// <param name="dropdownListOptions">下拉菜单控件配置项,除ItemSourceUrl、TextField、ValueField、ItemSource外其他都生效</param>
- /// <param name="htmlAttributes">自定义Html属性扩展,用Dictionary的方式定义,例如:new Dictionary<string, string> {
- /// { "style", "width: 100%;" }, { "name", "ddlUsers" }
- /// }
- /// </param>
- /// <returns></returns>
- public static MvcHtmlString SchoolYearDropDownList(this HtmlHelper htmlHelper,DropdownListOptions dropdownListOptions = null, System.Collections.Generic.IDictionary<string, string> htmlAttributes = null)
- {
- if (dropdownListOptions == null)
- dropdownListOptions = new DropdownListOptions();
- dropdownListOptions.ItemSourceUrl = UrlHelper.GenerateContentUrl("~/Common/SchoolYearDropDown", htmlHelper.ViewContext.HttpContext);
- if (dropdownListOptions.SelectedValue == null)
- {
- dropdownListOptions.SelectedValue = DropdownList.PLEASE_SELECT.ToString();
- }
- return htmlHelper.DropdownList(dropdownListOptions, htmlAttributes);
- }
- /// <summary>
- /// 绑定ViewModel的学年数下拉控件,下拉列出学年数,如:2015、2016、2017等等……
- /// </summary>
- /// <typeparam name="TModel"></typeparam>
- /// <typeparam name="TProperty"></typeparam>
- /// <param name="htmlHelper"></param>
- /// <param name="expression">定义绑定属性的lamda,如:(x => x.LoginID)</param>
- /// <param name="dropdownListOptions">下拉菜单控件配置项,除ItemSourceUrl、TextField、ValueField、ItemSource外其他都生效</param>
- /// <param name="htmlAttributes">自定义Html属性扩展,用Dictionary的方式定义,例如:new Dictionary<string, string> {
- /// { "style", "width: 100%;" }, { "name", "ddlUsers" }
- /// }
- /// </param>
- /// <returns></returns>
- public static MvcHtmlString SchoolYearDropDownListFor<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.ItemSourceUrl = UrlHelper.GenerateContentUrl("~/Common/SchoolYearDropDown", htmlHelper.ViewContext.HttpContext);
- if (string.IsNullOrEmpty(dropdownListOptions.ID))
- {
- dropdownListOptions.ID = fullHtmlFieldName;
- }
- dropdownListOptions.Name = fullHtmlFieldName;
- dropdownListOptions.SelectedValue = Convert.ToString((int)(modelMetadata.Model ?? DropdownList.PLEASE_SELECT));
- return htmlHelper.DropdownList(dropdownListOptions, htmlAttributes);
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="htmlHelper"></param>
- /// <param name="dictionaryCode"></param>
- /// <param name="dropdownListOptions"></param>
- /// <param name="htmlAttributes"></param>
- /// <returns></returns>
- private static MvcHtmlString ConvertToComboGrid(this HtmlHelper htmlHelper, string dictionaryCode, DropdownListOptions dropdownListOptions, IDictionary<string, string> htmlAttributes)
- {
- ComboGridOptions comboGridOption = new ComboGridOptions()
- {
- SelectedValue = dropdownListOptions.SelectedValue,
- TextField = dropdownListOptions.TextField ?? "Name",
- ValueField = dropdownListOptions.ValueField ?? "Value",
- OnSelect = dropdownListOptions.OnSelect,
- OnChange = dropdownListOptions.OnChange,
- Width = dropdownListOptions.Width,
- Height = dropdownListOptions.Height,
- IsEnabled = dropdownListOptions.IsEnabled,
- IsRequired = dropdownListOptions.IsRequired,
- IsAutoComplete = true,
- EmptyText = (dropdownListOptions.BindType == DropdownListBindType.SelectAll ? "全部" : (dropdownListOptions.BindType == DropdownListBindType.PleaseSelect ? "请选择" : ""))
- };
- comboGridOption.GridOptions = new DataGridOptions
- {
- Columns = new List<DataGridColumn>() {
- new BoundFieldColumn { FieldName="Value", Align=AlignStyle.Center },
- new BoundFieldColumn { FieldName="Name", Align=AlignStyle.Center, CustomFormatFun = dropdownListOptions.Formatter }
- },
- OnLoadSuccessFun = dropdownListOptions.OnLoadSuccess,
- IsShowTitle = false,
- IsCheckOnSelect = true,
- DataSourceUrl = UrlHelper.GenerateContentUrl("~/DictionaryItem/ComboGridList?dictionaryCode=" + dictionaryCode, htmlHelper.ViewContext.HttpContext),
- IsPagination = true,
- IsShowRowNumbers = true,
- IsSingleSelect = false
- };
- return MvcHtmlString.Create(ComboGrid.CreateControl(comboGridOption, htmlAttributes).Render());
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="htmlHelper"></param>
- /// <param name="dictionaryItem"></param>
- /// <param name="bindType"></param>
- /// <param name="comboGridOptions"></param>
- /// <returns></returns>
- private static ComboGridOptions InitComboGridOptions(this HtmlHelper htmlHelper, DictionaryItem dictionaryItem, DropdownListBindType bindType, ComboGridOptions comboGridOptions)
- {
- if (comboGridOptions == null)
- comboGridOptions = new ComboGridOptions();
- if (comboGridOptions.GridOptions == null)
- comboGridOptions.GridOptions = new DataGridOptions();
- if (string.IsNullOrEmpty(comboGridOptions.TextField))
- {
- comboGridOptions.TextField = "Name";
- }
- if (string.IsNullOrEmpty(comboGridOptions.ValueField))
- {
- comboGridOptions.ValueField = "Value";
- }
- if (string.IsNullOrEmpty(comboGridOptions.EmptyText))
- {
- comboGridOptions.EmptyText = (bindType == DropdownListBindType.SelectAll ? "全部" : (bindType == DropdownListBindType.PleaseSelect ? "请选择" : ""));
- }
- comboGridOptions.IsAutoComplete = comboGridOptions.IsAutoComplete ?? true;
- comboGridOptions.GridOptions.DataSourceUrl = UrlHelper.GenerateContentUrl("~/DictionaryItem/ComboGridList?dictionaryCode="
- + dictionaryItem.ToString(), htmlHelper.ViewContext.HttpContext);
- comboGridOptions.GridOptions.IsShowTitle = false;
- comboGridOptions.GridOptions.IsShowHeader = false;
- if (comboGridOptions.GridOptions.Columns == null || comboGridOptions.GridOptions.Columns.Count == 0)
- {
- comboGridOptions.GridOptions.Columns = new List<DataGridColumn>() {
- new BoundFieldColumn { FieldName="Name", Align=AlignStyle.Center }
- };
- }
- return comboGridOptions;
- }
- /// <summary>
- /// 字典下拉表格控件,下拉列出指定字典表中的枚举项
- /// </summary>
- /// <param name="htmlHelper"></param>
- /// <param name="dictionaryItem">指定要列出的字典类型</param>
- /// <param name="bindType">绑定类型,有三种方式,一般情况下,作为列表查询条件时,使用SelectAll,默认项显示"全部";
- /// 作为明细页面编辑控件时,使用PleaseSelect,默认项显示"请选择";
- /// 部分页面因为要求用户必须选择一个选项,例如报表的周期,这时候使用None,不显示默认项</param>
- /// <param name="comboGridOptions">下拉表格控件配置项,除GridOptions.ItemSourceUrl、EmptyText、TextField、ValueField外其他都生效</param>
- /// <param name="htmlAttributes">自定义Html属性扩展,用Dictionary的方式定义,例如:new Dictionary<string, string> {
- /// { "style", "width: 100%;" }, { "name", "ddlUsers" }
- /// }
- /// </param>
- /// <returns></returns>
- public static MvcHtmlString DictionaryComboGrid(this HtmlHelper htmlHelper, DictionaryItem dictionaryItem, DropdownListBindType bindType,
- ComboGridOptions comboGridOptions = null, System.Collections.Generic.IDictionary<string, string> htmlAttributes = null)
- {
- comboGridOptions = InitComboGridOptions(htmlHelper, dictionaryItem, bindType, comboGridOptions);
- return htmlHelper.ComboGrid(comboGridOptions, htmlAttributes);
- }
- /// <summary>
- /// 绑定ViewModel的字典下拉表格控件,下拉列出指定字典表中的枚举项
- /// </summary>
- /// <typeparam name="TModel"></typeparam>
- /// <typeparam name="TProperty"></typeparam>
- /// <param name="htmlHelper"></param>
- /// <param name="dictionaryItem">指定要列出的字典类型</param>
- /// <param name="expression">定义绑定属性的lamda,如:(x => x.LoginID)</param>
- /// <param name="bindType">绑定类型,有三种方式,一般情况下,作为列表查询条件时,使用SelectAll,默认项显示"全部";
- /// 作为明细页面编辑控件时,使用PleaseSelect,默认项显示"请选择";
- /// 部分页面因为要求用户必须选择一个选项,例如报表的周期,这时候使用None,不显示默认项</param>
- /// <param name="comboGridOptions">下拉表格控件配置项,除GridOptions.ItemSourceUrl、EmptyText、TextField、ValueField外其他都生效</param>
- /// <param name="htmlAttributes">自定义Html属性扩展,用Dictionary的方式定义,例如:new Dictionary<string, string> {
- /// { "style", "width: 100%;" }, { "name", "ddlUsers" }
- /// }
- /// </param>
- /// <returns></returns>
- public static MvcHtmlString DictionaryComboGridFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, DictionaryItem dictionaryItem, Expression<Func<TModel, TProperty>> expression, DropdownListBindType bindType,
- ComboGridOptions comboGridOptions = null, System.Collections.Generic.IDictionary<string, string> htmlAttributes = null)
- {
- comboGridOptions = InitComboGridOptions(htmlHelper, dictionaryItem, bindType, comboGridOptions);
- return htmlHelper.ComboGridFor(expression, comboGridOptions, htmlAttributes);
- }
- /// <summary>
- ///
- /// </summary>
- /// <typeparam name="TModel"></typeparam>
- /// <typeparam name="TProperty"></typeparam>
- /// <param name="htmlHelper"></param>
- /// <param name="expression"></param>
- /// <param name="dropdownListOptions"></param>
- /// <param name="htmlAttributes"></param>
- /// <returns></returns>
- public static MvcHtmlString WeekdayDropDownListFor<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 = BaseExtensions.WeekdayDropdownListItemList;
- if (string.IsNullOrEmpty(dropdownListOptions.ID))
- {
- dropdownListOptions.ID = fullHtmlFieldName;
- }
- dropdownListOptions.Name = fullHtmlFieldName;
- dropdownListOptions.SelectedValue = Convert.ToString((int)(modelMetadata.Model ?? DropdownList.PLEASE_SELECT));
- return htmlHelper.DropdownList(dropdownListOptions, htmlAttributes);
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="htmlHelper"></param>
- /// <param name="dropdownListOptions"></param>
- /// <param name="htmlAttributes"></param>
- /// <returns></returns>
- public static MvcHtmlString WeekdayDropDownList(this HtmlHelper htmlHelper, DropdownListOptions dropdownListOptions = null, System.Collections.Generic.IDictionary<string, string> htmlAttributes = null)
- {
- if (dropdownListOptions == null)
- {
- dropdownListOptions = new DropdownListOptions();
- }
- dropdownListOptions.ItemList = BaseExtensions.WeekdayDropdownListItemList;
- return htmlHelper.DropdownList(dropdownListOptions, htmlAttributes);
- }
- }
- }
|