Example #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后肯定是需要显示的值
        }
Example #2
0
        public override MvcHtmlString Html <TModel, TProperty>(HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression)
        {
            var propertyName = ExpressionHelper.GetExpressionText(expression);
            //var value = ValueExtensions.ValueFor(htmlHelper, expression);
            var value = PFMVCHelper.ExpressionValueFor(htmlHelper, expression);

            return(this.Html(htmlHelper, propertyName, value));
        }
Example #3
0
        public override MvcHtmlString Html <TModel, TProperty>(HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression)
        {
            var htmlAttributes = GetHtmlAttributes();
            var exp            = expression as Expression <Func <TModel, bool> >;

            if (exp != null)
            {
                return(htmlHelper.CheckBoxFor(expression as Expression <Func <TModel, bool> >, htmlAttributes));
            }
            else //上面For方法只支持非空bool型
            {
                var n = ExpressionHelper.GetExpressionText(expression);
                var v = PFMVCHelper.ExpressionValueFor(htmlHelper, expression);
                if (v == null)
                {
                    v = false;
                }
                return(htmlHelper.CheckBox(n, (bool)v, htmlAttributes));
            }
        }