Ejemplo n.º 1
0
        /// <summary>
        /// Renders a Bootstrap checkbox.
        /// </summary>
        /// <param name="htmlHelper">The <see cref="T:Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper" /> instance this method extends.</param>
        /// <param name="expression">Expression name, relative to the current model.</param>
        /// <param name="htmlAttributes">
        /// An <see cref="T:System.Object" /> that contains the HTML attributes for the checkbox element. Alternatively, an
        /// <see cref="T:System.Collections.Generic.IDictionary`2" /> instance containing the HTML
        /// attributes.
        /// </param>
        /// <param name="configAction">Action that implements checkbox configuration.</param>
        /// <returns>Checkbox html markup.</returns>
        /// <remarks>
        /// <para>
        /// Combines <see cref="P:Microsoft.AspNetCore.Mvc.ViewFeatures.TemplateInfo.HtmlFieldPrefix" /> and <paramref name="expression" /> to set
        /// checkbox element's "name" attribute. Sanitizes <paramref name="expression" /> to set checkbox element's "id"
        /// attribute.
        /// </para>
        /// <para>Determines checkbox element's "checked" attribute based on the following precedence:</para>
        /// <list type="number">
        /// <item>
        /// <see cref="T:Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary" /> entry for <paramref name="expression" /> (converted to a
        /// fully-qualified name) if entry exists and can be converted to a <see cref="T:System.Boolean" />.
        /// </item>
        /// <item>
        /// <see cref="T:Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary" /> entry for <paramref name="expression" /> (converted to a
        /// fully-qualified name) if entry exists and can be converted to a <see cref="T:System.Boolean" />.
        /// </item>
        /// <item>
        /// Linq expression based on <paramref name="expression" /> (converted to a fully-qualified name) run against
        /// current model if result is non-<c>null</c> and can be converted to a <see cref="T:System.Boolean" />. For example
        /// <c>string.Empty</c> identifies the current model and <c>"prop"</c> identifies the current model's "prop"
        /// property.
        /// </item>
        /// <item>Existing "checked" entry in <paramref name="htmlAttributes" /> if any.</item>
        /// <item>Otherwise, does not include a "checked" attribute.</item>
        /// </list>
        /// <para>
        /// In all but the <paramref name="htmlAttributes" /> and default cases, includes a "checked" attribute with
        /// value "checked" if the <see cref="T:System.Boolean" /> values is <c>true</c>; does not include the attribute otherwise.
        /// </para>
        /// </remarks>
        public static IHtmlContent MvcCoreBootstrapCheckBox(this IHtmlHelper htmlHelper, string expression, object htmlAttributes,
                                                            Action <MvcCoreBootstrapCheckBoxBuilder> configAction = null)
        {
            CheckBoxConfig config = new CheckBoxConfig();

            return(htmlHelper.Control(configAction, new MvcCoreBootstrapCheckBoxBuilder(config),
                                      new CheckBoxRenderer(config, new TooltipRenderer()), config, htmlHelper.CheckBox(expression, htmlAttributes)));
        }
        public CheckBoxOption(ConfigEntry <bool> configEntry, CheckBoxConfig config)
        {
            _originalValue = configEntry.Value;
            _configEntry   = configEntry;
            Config         = config;

            SetCategoryName(configEntry.Definition.Section, config);
            SetName(configEntry.Definition.Key, config);
            SetDescription(configEntry.Description.Description, config);
        }
Ejemplo n.º 3
0
        private static IHtmlContent CheckBoxFor <TModel>(this IHtmlHelper <TModel> htmlHelper,
                                                         Expression <Func <TModel, bool> > expression, Action <MvcCoreBootstrapCheckBoxBuilder> configAction,
                                                         CheckBoxConfig config)
        {
            FormConfig formConfig = htmlHelper.ViewBag.FormConfig as FormConfig;

            Debug.Assert(formConfig != null);
            if (htmlHelper == null)
            {
                throw new ArgumentNullException(nameof(htmlHelper));
            }
            if (expression == null)
            {
                throw new ArgumentNullException(nameof(expression));
            }

            config.ColumnWidths = formConfig.ColumnWidths;
            config.PropertyValidationMessages = formConfig.PropertyValidationMessages;
            configAction?.Invoke(new MvcCoreBootstrapCheckBoxBuilder(config));

            return(new CheckBoxRenderer(config, new TooltipRenderer()).Render(htmlHelper, expression));
        }
Ejemplo n.º 4
0
 internal MvcCoreBootstrapCheckBoxBuilder(CheckBoxConfig config)
 {
     _config = config;
 }
Ejemplo n.º 5
0
 public CheckBoxRenderer(CheckBoxConfig config, ITooltipRenderer tooltipRenderer)
     : base(config, tooltipRenderer)
 {
     _config = config;
 }