Beispiel #1
0
        public override void SetPropertyFor <TModel, TProperty>(HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression)
        {
            base.SetPropertyFor(htmlHelper, expression);
            //var t = typeof(TProperty);
            var t = PFDataHelper.GetNonnullType(typeof(TProperty));
            var v = PFMVCHelper.ExpressionValueFor(htmlHelper, expression);

            if (v != null)
            {
                if (t.IsEnum)
                {
                    _selectedValue = ((int)v).ToString();
                }
                else
                {
                    _selectedValue = v.ToString();
                }
            }
            if (t.IsEnum)
            {
                SetSelectList(PFDataHelper.EnumToKVList(t));
            }

            //_selectedValue = (PFMVCHelper.ExpressionValueFor(htmlHelper,expression)??"").ToString();
            //_selectedText = (PFMVCHelper.ExpressionValueFor(htmlHelper, expression) ?? "").ToString();//这里用text,是因为即便是enum,ToString后肯定是需要显示的值
        }