Пример #1
0
        public static IHtmlContent PassWordFormGroupInputFor <TModel, TValue>(
            this IHtmlHelper <TModel> htmlHelper,
            Expression <Func <TModel, TValue> > property,
            string placeholder,
            object labelAttributes   = null,
            object textBoxAttributes = null,
            bool localValidation     = true)
        {
            using (var writer = new StringWriter())
            {
                writer.Write("<div class='form-group'>");
                HtmlHelperLabelExtensions.LabelFor(
                    htmlHelper,
                    property,
                    labelAttributes)
                .WriteTo(writer, System.Text.Encodings.Web.HtmlEncoder.Default);

                HtmlHelperInputExtensions.TextBoxFor(
                    htmlHelper,
                    property,
                    textBoxAttributes ?? new { placeholder, @class = "form-control", @type = "password" })
                .WriteTo(writer, System.Text.Encodings.Web.HtmlEncoder.Default);

                if (localValidation)
                {
                    HtmlHelperValidationExtensions.ValidationMessageFor(
                        htmlHelper,
                        property)
                    .WriteTo(writer, System.Text.Encodings.Web.HtmlEncoder.Default);
                }
                writer.Write("</div>");
                return(new HtmlString(writer.ToString()));
            }
        }
Пример #2
0
        private static IHtmlContent GenerateEditor <TModel, TValue>(IHtmlHelper <TModel> html, Expression <Func <TModel, TValue> > expression, string toolTip, string errorMessage, IHtmlContent label)
        {
            IHtmlContent contents  = HtmlHelperEditorExtensions.EditorFor(html, expression, new { htmlAttributes = new { @class = "form-control", @title = toolTip } });
            IHtmlContent validator = HtmlHelperValidationExtensions.ValidationMessageFor(html, expression, errorMessage, new { @class = "text-danger" });

            string result = String.Concat("<div class=\"form-group\">",
                                          GetString(label),
                                          "<div class=\"col-md-8\">",
                                          GetString(contents),
                                          GetString(validator),
                                          "</div>",
                                          "</div>");

            return(new HtmlString(result));
        }