예제 #1
0
        public static IHtmlString CheckBoxFor <TModel, TR>(this HtmlHelpers <TModel> html,
                                                           Expression <Func <TModel, TR> > prop, object htmlAttributes) where TModel : class
        {
            var tag = HtmlTagBuilder.CreateCheckBoxFor(html, prop, htmlAttributes);

            return(tag != null ? new NonEncodedHtmlString(tag.ToString()) : NonEncodedHtmlString.Empty);
        }
        public void CheckboxForBoolPropertyWithDefValueFalseAsStringIsNoChecked()
        {
            var html = new HtmlHelpers <BooleanModel>(null, null, null);
            var tag  = HtmlTagBuilder.CreateCheckBoxFor(html, m => m.BooleanPropWithDefValueFalseAsString, null);

            Assert.IsNull(tag.Attribute("checked"));
        }
        public void CheckboxForBoolPropertyWithDefValueTrueIsChecked()
        {
            var html = new HtmlHelpers <BooleanModel>(null, null, null);
            var tag  = HtmlTagBuilder.CreateCheckBoxFor(html, m => m.BooleanPropWithDefValueTrue, null);

            Assert.IsTrue(tag.Attribute("checked").IsWithNoValue);
        }
        public void CheckboxForBoolPropertyIsCheckedIfPropertyIsTrue()
        {
            var model = new BooleanModel()
            {
                BooleanPropWithDefValueFalseAsString = true
            };
            var html = new HtmlHelpers <BooleanModel>(null, null, model);
            var tag  = HtmlTagBuilder.CreateCheckBoxFor(html, m => m.BooleanPropWithDefValueFalseAsString, null);

            Assert.IsTrue(tag.Attribute("checked").IsWithNoValue);
        }
예제 #5
0
        public static IHtmlString InputElementFor <TModel, TR>(this HtmlHelpers <TModel> html,
                                                               Expression <Func <TModel, TR> > prop, object htmlAttributes) where TModel : class
        {
            var property = prop.AsPropertyInfo();

            if (property == null)
            {
                return(NonEncodedHtmlString.Empty);
            }
            var inputType = GetInputTypeByProperty(property);
            var tag       = inputType == HtmlInputType.Checkbox ?
                            HtmlTagBuilder.CreateCheckBoxFor(html, prop, htmlAttributes) :
                            HtmlTagBuilder.CreateInputElementFor(html, prop, inputType, htmlAttributes);

            return(tag != null ? new NonEncodedHtmlString(tag.ToString()) : NonEncodedHtmlString.Empty);
        }