public static IHtmlString LabelFor <TModel, TR>(this HtmlHelpers <TModel> html,
                                                        Expression <Func <TModel, TR> > prop, object htmlAttributes) where TModel : class
        {
            var label = HtmlTagBuilder.CreateLabelFor(prop, htmlAttributes);

            return(label != null ? new NonEncodedHtmlString(label.ToString()) : NonEncodedHtmlString.Empty);
        }
Example #2
0
        public void LabelForUsesDisplayNameIfFound()
        {
            var tag = HtmlTagBuilder.CreateLabelFor <LabelModel, string>(lm => lm.AnotherProperty, null);

            Assert.AreEqual("Another Property", tag.RawContent);
        }
Example #3
0
        public void LabelForUsesPropertyNameByDefault()
        {
            var tag = HtmlTagBuilder.CreateLabelFor <LabelModel, string>(lm => lm.SomeProperty, null);

            Assert.AreEqual("SomeProperty", tag.RawContent);
        }