public static HtmlTag FileInputBlock <T>(this HtmlHelper <T> helper, Expression <Func <T, object> > expression) where T : class
        {
            var accept = Property.From(expression).GetCustomAttributes <AcceptAttribute>().SingleOrDefault();

            Action <HtmlTag> action = input =>
            {
                input.Attr("type", "file");
                input.AddClass("form-control");
                if (accept != null)
                {
                    input.Attr("accept", accept.FileTypeSpecifier);
                }
            };

            return(helper.InputBlock(expression, null, null, action));
        }
Пример #2
0
        public static HtmlTag InputTextAreaBlock <T>(this IHtmlHelper <T> helper, Expression <Func <T, object> > expression, string value = null, string placeholderText = null, string helpText = null, Action <HtmlTag> inputModifier = null, string customLabelText = null) where T : class
        {
            Preconditions.ThrowIfNull(helper, nameof(helper));
            Preconditions.ThrowIfNull(expression, nameof(expression));

            var label = helper.Label(expression);

            if (customLabelText != null)
            {
                label.Text(customLabelText);
            }
            label = label.WrapWith(new DivTag().AddClasses("col-xs-4", "text-right"));

            var expressionPropertyName = Property.From(expression).Name;

            var textAreaInput = new HtmlTag("textarea")
                                .Id(expressionPropertyName)
                                .Name(expressionPropertyName)
                                .AddClass("form-control");

            if (!string.IsNullOrEmpty(value))
            {
                textAreaInput.AppendText(value);
            }

            if (!string.IsNullOrEmpty(placeholderText))
            {
                textAreaInput.AddPlaceholder(placeholderText);
            }
            inputModifier?.Invoke(textAreaInput);

            textAreaInput = textAreaInput.WrapWith(new DivTag().AddClasses("col-xs-6", "text-left"));
            textAreaInput.Append(new HtmlTag("small").AppendText(helpText).AddClass("text-muted"));

            return(FormBlock(label, textAreaInput, HtmlTag.Empty()));
        }