public override HtmlTag Build(ElementRequest request) { Action<SelectTag> action = x => { var value = request.RawValue is Entity ? ((Entity)request.RawValue).EntityId : request.RawValue; var propertyName = request.ToAccessorDef().Accessor.FieldName; var listPropertyInfo = request.ToAccessorDef().ModelType.GetProperty(propertyName+"List"); var selectListItems = listPropertyInfo.GetValue(request.Model, null) as IEnumerable<SelectListItem>; if (selectListItems == null) return; selectListItems.ForEachItem(option=> x.Option(option.Text, option.Value.IsNotEmpty() ? option.Value: "")); if ( value != null && value.ToString().IsNotEmpty()) { x.SelectByValue(value.ToString()); } x.AddClass("mf_fixedWidthDropdown"); x.AddClass("fixedWidthDropdown"); }; return new SelectTag(action); }
public override HtmlTag Build(ElementRequest request) { Action<SelectTag> action = x => { var value = request.RawValue; var propertyName = request.ToAccessorDef().Accessor.FieldName; var listPropertyInfo = request.ToAccessorDef().ModelType.GetProperty(propertyName + "List"); var dictionary = listPropertyInfo.GetValue(request.Model, null) as IDictionary<string, IEnumerable<SelectListItem>>; if (dictionary == null) return; x.Option(CCCoreLocalizationKeys.SELECT_ITEM.ToString(),""); dictionary.Keys.ForEachItem(key => { x.OptionGroup(key); dictionary[key].ForEachItem(l => x.Option(l.Text, l.Value+"_"+key)); }); if (value != null && value.ToString().IsNotEmpty()) { x.SelectByValue(value.ToString()); } }; return new SelectTag(action); }
public HtmlTag Build(ElementRequest request) { return _creators[request.ToAccessorDef()](request); }