public override HtmlTag Build(ElementRequest request)
        {
            Action<SelectTag> action = x =>
                                           {
            //                                               var value = request.RawValue is Entity ? ((Entity)request.RawValue).EntityId : request.RawValue;
                                               var value = 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("fixedWidthDropdown");
                                           };
            return new SelectTag(action);
        }
Exemplo n.º 2
0
        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("SelectItem","");
                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);
        }
Exemplo n.º 3
0
 public HtmlTag Build(ElementRequest request)
 {
     return _creators[request.ToAccessorDef()](request);
 }