Example #1
0
        public MvcHtmlString LabelFor <TProperty>(Expression <Func <TModel, TProperty> > expression, IDictionary <string, object> htmlAttributes)
        {
            int labelSize = BsHelper.GetLabelSize();

            if (htmlAttributes == null)
            {
                htmlAttributes = new Dictionary <string, object>();
            }

            if (htmlAttributes.ContainsKey("class"))
            {
                htmlAttributes["class"] += " control-label col-sm-" + labelSize.ToString();
            }
            else
            {
                htmlAttributes["class"] = "control-label col-sm-" + labelSize.ToString();
            }

            ViewDataDictionary <TModel> viewData = new ViewDataDictionary <TModel>(HtmlHelper.ViewData);

            ModelMetadata metadata      = ModelMetadata.FromLambdaExpression(expression, viewData);
            string        htmlFieldName = ExpressionHelper.GetExpressionText(expression);

            if (metadata.DisplayName == null)
            {
                metadata.DisplayName = BsHelper.SplitCamelCase(metadata.PropertyName ?? htmlFieldName.Split('.').Last());
            }

            return(HtmlHelper.LabelFor(expression, metadata.DisplayName, htmlAttributes));
        }