Exemplo n.º 1
0
        /// <summary>
        /// Renders Bootstrap radio buttons for an enum model property.
        /// The possible values for the property is extracted from the enum type.
        /// </summary>
        /// <param name="htmlHelper">Html helper instance.</param>
        /// <param name="expression">Model property expression.</param>
        /// <param name="labels">Labels for each radio button (value).</param>
        /// <param name="configAction">Action that implements radio buttons configuration.</param>
        /// <returns>Radio buttons html markup.</returns>
        public static IHtmlContent MvcCoreBootstrapRadioButtonsFor <TModel, TResult>(this IHtmlHelper <TModel> htmlHelper,
                                                                                     Expression <Func <TModel, TResult> > expression, IEnumerable <string> labels,
                                                                                     Action <MvcCoreBootstrapRadioButtonsBuilder> configAction = null) where TModel : class
        {
            RadioButtonsConfig config = new RadioButtonsConfig();

            if (expression.ReturnType.GetTypeInfo().IsEnum || expression.ReturnType.GenericTypeArguments[0].GetTypeInfo().IsEnum)
            {
                Array values = Enum.GetValues(expression.ReturnType.GenericTypeArguments[0]);

                if (values.Length != labels.Count())
                {
                    throw new ArgumentException("Values and labels must have the same count");
                }

                for (int i = 0; i < values.Length; i++)
                {
                    config.RadioButtons.Add(new RadioButtonConfig
                    {
                        Value = values.GetValue(i).ToString(),
                        Label = labels.ElementAt(i),
                    });
                }
            }
            else
            {
                throw new ArgumentException("Model property is not an enum");
            }

            return(htmlHelper.ControlFor(expression, configAction, new MvcCoreBootstrapRadioButtonsBuilder(config),
                                         new RadioButtonsRenderer(config, new TooltipRenderer()), config));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Renders Bootstrap radio buttons. Each radio button is configrued individually.
        /// </summary>
        /// <param name="htmlHelper">Html helper instance.</param>
        /// <param name="expression">Expression name, relative to the current model.</param>
        /// <param name="configAction">Action that implements radio buttons configuration.</param>
        /// <returns>Radio buttons html markup.</returns>
        public static IHtmlContent MvcCoreBootstrapRadioButtons(this IHtmlHelper htmlHelper, string expression,
                                                                Action <MvcCoreBootstrapRadioButtonsBuilder> configAction)
        {
            RadioButtonsConfig config = new RadioButtonsConfig();

            return(htmlHelper.Control(configAction, new MvcCoreBootstrapRadioButtonsBuilder(config),
                                      new RadioButtonsRenderer(config, new TooltipRenderer()), config, htmlHelper.RadioButton(expression, 0)));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Renders Bootstrap radio buttons. Each radio button is configrued individually.
        /// </summary>
        /// <param name="htmlHelper">Html helper instance.</param>
        /// <param name="expression">Model property expression.</param>
        /// <param name="configAction">Action that implements radio buttons configuration.</param>
        /// <returns>Radio buttons html markup.</returns>
        public static IHtmlContent MvcCoreBootstrapRadioButtonsFor <TModel, TResult>(this IHtmlHelper <TModel> htmlHelper,
                                                                                     Expression <Func <TModel, TResult> > expression,
                                                                                     Action <MvcCoreBootstrapRadioButtonsBuilder> configAction)
        {
            RadioButtonsConfig config = new RadioButtonsConfig();

            return(htmlHelper.ControlFor(expression, configAction, new MvcCoreBootstrapRadioButtonsBuilder(config),
                                         new RadioButtonsRenderer(config, new TooltipRenderer()), config));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Renders Bootstrap buttons.
        /// </summary>
        /// <param name="htmlHelper">Html helper instance.</param>
        /// <param name="expression">Expression name, relative to the current model.</param>
        /// <param name="values">Radio buttons values.</param>
        /// <param name="labels">Labels for each radio button (value).</param>
        /// <param name="configAction">Action that implements radio buttons configuration.</param>
        /// <returns>Radio buttons html markup.</returns>
        public static IHtmlContent MvcCoreBootstrapRadioButtons(this IHtmlHelper htmlHelper, string expression,
                                                                IEnumerable <object> values, IEnumerable <string> labels,
                                                                Action <MvcCoreBootstrapRadioButtonsBuilder> configAction = null)
        {
            RadioButtonsConfig config = new RadioButtonsConfig();

            if (values.Count() != labels.Count())
            {
                throw new ArgumentException("Values and labels must have the same count");
            }

            for (int i = 0; i < values.Count(); i++)
            {
                config.RadioButtons.Add(new RadioButtonConfig
                {
                    Value = values.ElementAt(i),
                    Label = labels.ElementAt(i),
                });
            }

            return(htmlHelper.Control(configAction, new MvcCoreBootstrapRadioButtonsBuilder(config),
                                      new RadioButtonsRenderer(config, new TooltipRenderer()), config, htmlHelper.RadioButton(expression, 0)));
        }
 public RadioButtonsRenderer(RadioButtonsConfig config, ITooltipRenderer tooltipRenderer)
     : base(config, tooltipRenderer)
 {
     _config = config;
 }
 internal MvcCoreBootstrapRadioButtonsBuilder(RadioButtonsConfig config)
 {
     _config = config;
 }