/// <summary> /// 字典下拉列表 /// </summary> /// <typeparam name="TModel"></typeparam> /// <typeparam name="TProperty"></typeparam> /// <param name="helper"></param> /// <param name="expression"></param> /// <param name="parentId">父级字典ID</param> /// <param name="nullValue">要显示的空项的值,null则不会显示空项</param> /// <param name="nullDisplay">要显示的空项的文本,null则会显示nullValue</param> /// <param name="additionalViewData">附加数据</param> /// <param name="templateName">模版名</param> /// <returns></returns> static MvcHtmlString DicEditorHelper <TModel, TProperty>(this HtmlHelper <TModel> helper, Expression <Func <TModel, TProperty> > expression, ZLERP.Model.Enums.DicEnum parentId, string nullValue, string nullDisplay, object additionalViewData, string templateName = "DicDropDown") { string pId = parentId.ToString(); if (helper.ViewData.ContainsKey(pId)) { //insert null value if (nullValue != null) { var dic = helper.ViewData[pId] as IList <Dic>; nullDisplay = string.IsNullOrEmpty(nullDisplay) ? nullValue : nullDisplay; if (dic.Where(p => p.TreeCode == nullValue && p.DicName == nullDisplay).Count() == 0) { dic.Insert(0, new Dic { TreeCode = nullValue, DicName = nullDisplay }); } } IEnumerable <KeyValuePair <string, object> > routeValueDictionary = new RouteValueDictionary(new { ParentID = pId }).Concat(new RouteValueDictionary(additionalViewData)); foreach (KeyValuePair <string, object> pair in routeValueDictionary) { helper.ViewDataContainer.ViewData[pair.Key] = pair.Value; } return(helper.EditorFor(expression, templateName)); } else { return(MvcHtmlString.Empty); } }
public static MvcHtmlString DicEidtor(this HtmlHelper helper, string fieldName, string id, ZLERP.Model.Enums.DicEnum parentId) { string pId = parentId.ToString(); return(helper.Editor(fieldName, "DicDropDown", new { ParentID = pId, id = id })); }