예제 #1
0
        public static MvcHtmlString AppLabel(this HtmlHelper htmlHelper, string text, object htmlAttributes = null)
        {
            var control = new RenderLabel();

            control.Text = text;

            HtmlAttributes(control, htmlAttributes);

            return(MvcHtmlString.Create(control.ToString()));
        }
예제 #2
0
        public static MvcHtmlString AppLabelFor <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, object htmlAttributes = null)
        {
            var           control  = new RenderLabel();
            ModelMetadata metadata = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData);

            control.For = metadata.PropertyName;

            if (!string.IsNullOrEmpty(metadata.DisplayName))
            {
                control.Text = metadata.DisplayName;
            }
            else
            {
                control.Text = metadata.PropertyName.Replace("_", " ");
            }

            HtmlAttributes(control, htmlAttributes);

            return(MvcHtmlString.Create(control.ToString()));
        }