Example #1
0
        public static MvcHtmlString CheckBox(this AjaxHelper ajaxHelper,
                                             string name,
                                             bool?isChecked  = null,
                                             string cssClass = null,
                                             string dir      = null,
                                             bool disabled   = false,
                                             string id       = null,
                                             string lang     = null,
                                             int?maxLength   = null,
                                             bool readOnly   = false,
                                             int?size        = null,
                                             string style    = null,
                                             int?tabIndex    = null,
                                             string title    = null,
                                             string dataBind = null)
        {
            HtmlHelper htmlHelper = ajaxHelper.GetHtmlHelper();

            if (dataBind == null)
            {
                dataBind = "checked: " + name;
            }

            IDictionary <string, object> htmlAttributes = InputAttributes(
                name, cssClass, dir, disabled, id, lang, maxLength, readOnly, size, style, tabIndex, title, dataBind);

            return(isChecked.HasValue
                       ? htmlHelper.CheckBox(name, isChecked.Value, htmlAttributes)
                       : htmlHelper.CheckBox(name, htmlAttributes));
        }
Example #2
0
        public void CheckboxWithNonBooleanModelValue()
        {
            // Arrange
            var modelState = new ModelStateDictionary();

            modelState.SetModelValue("foo", Boolean.TrueString);
            HtmlHelper helper = HtmlHelperFactory.Create(modelState);

            // Act
            var html = helper.CheckBox("foo");

            // Assert
            Assert.Equal(
                @"<input checked=""checked"" id=""foo"" name=""foo"" type=""checkbox"" />",
                html.ToHtmlString()
                );

            modelState.SetModelValue("foo", new object());
            helper = HtmlHelperFactory.Create(modelState);

            // Act and Assert
            Assert.Throws <InvalidOperationException>(
                () => helper.CheckBox("foo"),
                "The parameter conversion from type \"System.Object\" to type \"System.Boolean\" failed because no "
                + "type converter can convert between these types."
                );
        }
Example #3
0
        public void CheckboxWithModelAndExplictValue()
        {
            // Arrange
            var modelState = new ModelStateDictionary();

            modelState.SetModelValue("foo", false);
            HtmlHelper helper = new HtmlHelper(modelState);

            // Act
            var html = helper.CheckBox("foo", true);

            // Assert
            Assert.AreEqual(@"<input checked=""checked"" id=""foo"" name=""foo"" type=""checkbox"" />",
                            html.ToHtmlString());


            modelState.SetModelValue("foo", true);

            // Act
            html = helper.CheckBox("foo", false);

            // Assert
            Assert.AreEqual(@"<input id=""foo"" name=""foo"" type=""checkbox"" />",
                            html.ToHtmlString());
        }
        public static MvcHtmlString CheckBox(
            this HtmlHelper htmlHelper,
            string name,
            bool?isChecked  = null,
            string cssClass = null,
            string dir      = null,
            bool disabled   = false,
            string id       = null,
            string lang     = null,
            int?maxLength   = null,
            bool readOnly   = false,
            int?size        = null,
            string style    = null,
            int?tabIndex    = null,
            string title    = null
            )
        {
            var htmlAttributes = InputAttributes(
                cssClass,
                dir,
                disabled,
                id,
                lang,
                maxLength,
                readOnly,
                size,
                style,
                tabIndex,
                title
                );

            return(isChecked.HasValue
              ? htmlHelper.CheckBox(name, isChecked.Value, htmlAttributes)
              : htmlHelper.CheckBox(name, htmlAttributes));
        }
        public void CheckboxWithEmptyNameThrows()
        {
            // Arrange
            HtmlHelper helper = HtmlHelperFactory.Create();

            // Act and assert
            Assert.ThrowsArgumentNullOrEmptyString(() => helper.CheckBox(null), "name");
            Assert.ThrowsArgumentNullOrEmptyString(() => helper.CheckBox(String.Empty), "name");
        }
Example #6
0
        public void CheckboxWithEmptyNameThrows()
        {
            // Arrange
            HtmlHelper helper = new HtmlHelper(new ModelStateDictionary());

            // Act and assert
            ExceptionAssert.ThrowsArgNullOrEmpty(() => helper.CheckBox(null), "name");
            ExceptionAssert.ThrowsArgNullOrEmpty(() => helper.CheckBox(String.Empty), "name");
        }
Example #7
0
 public static string SearchOcrCheckBox(this HtmlHelper htmlHelper, string name, string label, bool allowOCR)
 {
     if (allowOCR)
     {
         return(string.Format("{0}<label for=\"{1}\">{2}</label>", htmlHelper.CheckBox(name, false), name, label));
     }
     else
     {
         return(string.Format("{0}<label for=\"{1}\">{2}</label>", htmlHelper.CheckBox(name, false, new { Disabled = "disabled" }), name, label));
     }
 }
        /// <summary>
        /// Returns a checkbox for nullable bool (bool?) model properties
        /// </summary>
        /// <param name="htmlHelper">The HTML helper instance that this method extends.</param>
        /// <param name="expression">An expression that contains the property to render</param>
        public static MvcHtmlString CheckBoxNullableFor <TModel, TBool>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TBool> > expression)
        {
            var metadata = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData);
            var value    = (metadata.Model as bool?).HasValue && (metadata.Model as bool?).GetValueOrDefault();

            return(htmlHelper.CheckBox(ExpressionHelper.GetExpressionText(expression), value));
        }
Example #9
0
        public override MvcHtmlString WriteInput(HtmlHelper helper, object htmlAttributes)
        {
            IDictionary <string, object> efHtmlAttributes = new RouteValueDictionary(htmlAttributes);

            AddCommonHtmlAttributes(efHtmlAttributes);
            return(helper.CheckBox(this.InputName, this.IsChecked, efHtmlAttributes));
        }
Example #10
0
        public static IHtmlString BCheckBoxFor <TModel>(this HtmlHelper <TModel> helper, Expression <Func <TModel, bool?> > expression, object htmlAttributes = null)
        {
            var           _htmlAttr = new RouteValueDictionary(htmlAttributes ?? new Dictionary <string, object>());
            ModelMetadata metadata  = ModelMetadata.FromLambdaExpression(expression, helper.ViewData);

            bool?isChecked = null;

            if (metadata.Model != null)
            {
                bool modelChecked;
                if (bool.TryParse(metadata.Model.ToString(), out modelChecked))
                {
                    isChecked = modelChecked;
                }
            }
            if (!_htmlAttr.ContainsKey("data-model"))
            {
                _htmlAttr.Add("data-model", metadata.PropertyName);
            }

            // data-type
            if (!_htmlAttr.ContainsKey("data-type"))
            {
                _htmlAttr.Add("data-type", metadata.IsNullableValueType ? Nullable.GetUnderlyingType(metadata.ModelType.UnderlyingSystemType).Name : metadata.ModelType.Name);
            }

            return(helper.CheckBox(ExpressionHelper.GetExpressionText(expression), isChecked ?? false, _htmlAttr));
        }
        private static StringBuilder BuildCheckBoxListItems(this HtmlHelper htmlHelper, string name, IList <CheckBoxListItem> list)
        {
            var listItemBuilder = new StringBuilder();

            for (var i = 0; i < list.Count(); i++)
            {
                var item = list[i];

                var checkbox = htmlHelper.CheckBox(GetChildControlName(name, i, "IsChecked"), item.IsChecked);
                var text     = htmlHelper.Hidden(GetChildControlName(name, i, "Text"), item.Text);
                var value    = htmlHelper.Hidden(GetChildControlName(name, i, "Value"), item.Value);

                var sb = new StringBuilder();
                sb.AppendLine("<div class=\"checkbox\">");
                sb.AppendLine("<label>");
                sb.AppendLine(checkbox.ToHtmlString());
                sb.AppendLine(text.ToHtmlString());
                sb.AppendLine(value.ToHtmlString());
                sb.AppendLine(HttpUtility.HtmlEncode(item.Text));
                sb.AppendLine("</label>");
                sb.AppendLine("</div>");

                listItemBuilder.AppendLine(sb.ToString());
            }

            return(listItemBuilder);
        }
Example #12
0
        /// <summary>
        /// CheckBox chỉ có thuộc tính Name
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static MvcHtmlString VnrCheckBox(this HtmlHelper helper, string name)
        {
            var result = new StringBuilder();

            result.Append(helper.CheckBox(name, new { @class = "k-checkbox" }));
            return(MvcHtmlString.Create(result.ToString()));
        }
        public static IHtmlString CheckboxList(this HtmlHelper helper, string name, IEnumerable <SelectListItem> items)
        {
            TagBuilder ulTag = new TagBuilder("ul");

            ulTag.AddCssClass("checkbox-list");

            foreach (var item in items)
            {
                var liTag       = new TagBuilder("li");
                var ckValue     = item.Value ?? item.Text;
                var ckId        = name + "_" + ckValue;
                var checkboxTag = helper.CheckBox(name, item.Selected, new { value = ckValue, id = ckId }); //helper.RadioButton(name, rbValue, item.Selected, new { id = rbId });

                var labelTag = new TagBuilder("label");
                labelTag.MergeAttribute("for", ckId);
                labelTag.MergeAttribute("class", "inline");
                labelTag.InnerHtml = item.Text ?? item.Value;

                liTag.InnerHtml = checkboxTag.ToString() + labelTag.ToString();

                ulTag.InnerHtml += liTag.ToString();
            }

            return(new HtmlString(ulTag.ToString()));
        }
Example #14
0
        public override string FilterRender(HtmlHelper htmlHelper)
        {
            string SelectedValue = htmlHelper.ViewContext.HttpContext.Request.QueryString[Name];

            if (FilterSource != null)
            {
                SelectListItem item = FilterSource.FirstOrDefault(n => n.Value == SelectedValue);
                if (item != null)
                {
                    item.Selected = true;
                }
                return(htmlHelper.DropDownList(base.Name, FilterSource, "Seçiniz", new { @class = "form-control" }).ToString());
            }

            if (GetMemberType() == typeof(int))
            {
                return(htmlHelper.TextBox(Name, SelectedValue, new { type = "number", @class = "form-control" }).ToString());
            }
            else if (GetMemberType() == typeof(string))
            {
                return(htmlHelper.TextBox(Name, SelectedValue, new { @class = "form-control" }).ToString());
            }
            else if (GetMemberType() == typeof(DateTime))
            {
                return(htmlHelper.TextBox(Name, SelectedValue, new { @class = "form-control" }).ToString());
            }
            else if (GetMemberType() == typeof(bool))
            {
                return(htmlHelper.CheckBox(Name, SelectedValue == "1").ToString());
            }
            else
            {
                return("");
            }
        }
Example #15
0
        public static IHtmlString Display(this HtmlHelper html, DataRow model, DataColumn field)
        {
            var value = model != null ? model[field] : null;

            value = value is DBNull ? null : value;
            if (field.DataType.Equals(typeof(string)))
            {
                return(MvcHtmlString.Create((value ?? "").ToString()));
            }
            if (field.DataType.Equals(typeof(int)))
            {
                return(MvcHtmlString.Create((value ?? "").ToString()));
            }
            if (field.DataType.Equals(typeof(double)))
            {
                return(MvcHtmlString.Create((value ?? "").ToString()));
            }
            if (field.DataType.Equals(typeof(DateTime)))
            {
                return(MvcHtmlString.Create(value != null ? ((DateTime)value).ToShortDateString() : null));
            }
            if (field.DataType.Equals(typeof(bool)))
            {
                return(html.CheckBox("check", value != null ? (bool)value : false, new { disabled = true }));
            }
            throw new NotImplementedException(field.ColumnName);
        }
Example #16
0
        public static MvcHtmlString CustomCheckBox(this HtmlHelper htmlHelper, string name, string text, object htmlAttributes)
        {
            string spanOpen       = "<span class='mask-checkbox'>";
            string customCheckBox = htmlHelper.CheckBox(name, htmlAttributes).ToString();
            string labelText      = string.IsNullOrEmpty(text) ? name : text;

            TagBuilder tag = new TagBuilder("label");

            tag.SetInnerText(labelText);
            var htmlAttributesDict = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);

            foreach (var attribute in htmlAttributesDict)
            {
                if (attribute.Key == "class")
                {
                    if (attribute.Value.ToString().Contains("hidden-text"))
                    {
                        tag.AddCssClass("hidden-text block-element");
                    }
                }
            }
            string label       = tag.ToString(TagRenderMode.Normal);
            string spanClose   = "</span>";
            string icon        = "<i class='icon'></i>";
            string CheckBoxFor = spanOpen + customCheckBox + icon + spanClose + label;

            return(new MvcHtmlString(CheckBoxFor));
        }
Example #17
0
        public static IHtmlString Editor(this HtmlHelper html, DataRow model, DataColumn field)
        {
            var value = model != null ? model[field] : null;

            value = value is DBNull ? null : value;
            if (field.DataType.Equals(typeof(string)))
            {
                return(html.TextBox(field.ColumnName, value ?? ""));
            }
            if (field.DataType.Equals(typeof(int)))
            {
                return(html.TextBox(field.ColumnName, value ?? "", new { type = "number" }));
            }
            if (field.DataType.Equals(typeof(double)))
            {
                return(html.TextBox(field.ColumnName, value ?? ""));
            }
            if (field.DataType.Equals(typeof(DateTime)))
            {
                return(html.TextBox(field.ColumnName, value != null ? ((DateTime)value).ToShortDateString() : "", new { type = "date" }));
            }
            if (field.DataType.Equals(typeof(bool)))
            {
                return(html.CheckBox(field.ColumnName, value != null ? (bool)value : false));
            }
            throw new NotImplementedException(field.ColumnName);
        }
Example #18
0
        /// <summary>
        /// Generate ace checkbox
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <param name="label"></param>
        /// <param name="htmlAttributes"></param>
        /// <returns></returns>
        public static MvcHtmlString AceCheckBox(this HtmlHelper helper, string name, bool value = false, string label = "", object htmlAttributes = null)
        {
            var attributes = htmlAttributes != null
                ? new RouteValueDictionary(htmlAttributes)
                : new RouteValueDictionary();

            //Fix under score
            attributes.FixUnderScoreAttribute();

            if (attributes["class"] != null && !attributes["class"].ToString().Split(' ').Contains("ace"))
            {
                attributes["class"] = attributes["class"] + " ace";
            }
            else
            {
                attributes.Add("class", "ace");
            }

            var html = new StringBuilder();

            html.Append(helper.CheckBox(name, value, attributes));

            var tag = new TagBuilder("label");

            tag.SetInnerText(string.Format(" {0}", label));
            tag.Attributes.Add("class", "lbl");
            tag.Attributes.Add("for", name);

            html.Append(tag.ToString(TagRenderMode.Normal));

            return(MvcHtmlString.Create(html.ToString()));
        }
Example #19
0
 /// <summary>
 ///     Check box extension to allow custom prefix
 /// </summary>
 /// <typeparam name="TModel">The model type</typeparam>
 /// <typeparam name="TProperty">The type of the property</typeparam>
 /// <param name="htmlHelper">The HTML helper class</param>
 /// <param name="prefix">The prefix to prepend to the name and id</param>
 /// <param name="expression">The LINQ expression to get the value</param>
 /// <param name="htmlAttributes">The attributes to be added to the HTML</param>
 /// <returns>An HTML string</returns>
 public static MvcHtmlString CheckBoxFor <TModel>(this HtmlHelper <TModel> htmlHelper, string prefix,
                                                  Expression <Func <TModel, bool> > expression, object htmlAttributes)
 {
     return(htmlHelper.CheckBox($"{prefix}{ExpressionHelper.GetExpressionText(expression)}",
                                (bool)ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData).Model,
                                htmlAttributes));
 }
Example #20
0
        public static MvcHtmlString CustomCheckBox(this HtmlHelper htmlHelper, string name, bool lessHiddenField = false, object htmlAttributes = null)
        {
            var checkBoxWithHidden = htmlHelper.CheckBox(name, htmlAttributes).ToHtmlString().Trim();
            var pureCheckBox       = checkBoxWithHidden.Substring(0, checkBoxWithHidden.IndexOf("<input", 1, StringComparison.Ordinal));

            return(lessHiddenField ? new MvcHtmlString(pureCheckBox) : new MvcHtmlString(checkBoxWithHidden));
        }
Example #21
0
        public static MvcHtmlString CheckBoxWithValue(HtmlHelper htmlHelper, string name, bool isChecked, string value)
        {
            string     fullHtmlFieldName = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(name);
            ModelState modelState;

            if (htmlHelper.ViewData.ModelState.TryGetValue(fullHtmlFieldName, out modelState))
            {
                htmlHelper.ViewData.ModelState.SetModelValue(fullHtmlFieldName, new ValueProviderResult(isChecked, isChecked.ToString(), CultureInfo.CurrentCulture));
            }
            MvcHtmlString html;

            try
            {
                html = htmlHelper.CheckBox(name, isChecked);
            }
            finally
            {
                if (null != modelState)
                {
                    htmlHelper.ViewData.ModelState[fullHtmlFieldName] = modelState;
                }
            }
            string   htmlString = html.ToHtmlString();
            var      index      = htmlString.LastIndexOf('<');
            XElement element    = XElement.Parse(htmlString.Substring(0, index));

            element.SetAttributeValue("value", value);
            return(new MvcHtmlString(element.ToString()));
        }
Example #22
0
        public static MvcHtmlString SimpleCheckBox(this HtmlHelper htmlHelper, string name, object htmlAttributes)
        {
            string checkBoxWithHidden = htmlHelper.CheckBox(name, htmlAttributes).ToHtmlString().Trim();
            string pureCheckBox       = checkBoxWithHidden.Substring(0, checkBoxWithHidden.IndexOf("<input", 1));

            return(new MvcHtmlString(pureCheckBox));
        }
Example #23
0
        public static string NotificationList <T> (this HtmlHelper <T> html, string postUrl, IEnumerable <NotificationInfo> nots)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("<div id='notification-summary' postUrl='" + postUrl + "'><p>");
            sb.Append("<span id='notification-summary-list'></span>");
            sb.Append("<br><br><a href='#' id='notification-change-button' class='button'>Change Subscriptions</a>");
            sb.Append("</div></p>");

            sb.Append("<div id='notification-selector' style='display:none'>");
            sb.Append("<p>Select the notifications you want to subscribe to:</p>");
            sb.Append("<p>");

            foreach (var not in nots)
            {
                if (not.IsGroup)
                {
                    sb.Append("<p><b>").Append(not.Name).Append("</b></p>");
                }
                else
                {
                    sb.Append(html.CheckBox(not.Id, not.Enabled, new { nname = not.Name }));
                    sb.Append(not.Name).Append("<br>");
                }
            }

            sb.Append("</p><p>");
            sb.Append("<a href='#' id='notification-done-button' class='button'>Done</a>");
            sb.Append("</p></div>");
            return(sb.ToString());
        }
Example #24
0
        public static MvcHtmlString CheckBoxEx(this HtmlHelper htmlHelper, string name, string lable, bool isChecked = false, bool isDisabled = false, object htmlAttributes = null)
        {
            var attributes = new Dictionary <string, object>();
            var id         = name;

            attributes.Add("class", "custom-control-input");
            if (isDisabled)
            {
                attributes.Add("disabled", "disabled");
            }
            if (htmlAttributes != null)
            {
                foreach (PropertyInfo property in htmlAttributes.GetType().GetProperties())
                {
                    object propertyValue = property.GetValue(htmlAttributes, null);
                    attributes.Add(property.Name, propertyValue);
                    if (property.Name == "id")
                    {
                        id = propertyValue.ToString();
                    }
                }
            }
            string html = "<div class='custom-control custom-checkbox'>" +
                          htmlHelper.CheckBox(name, isChecked, attributes) +
                          "<label for='" + id + "' class='custom-control-label font-weight-normal'>" + lable + "</label>" +
                          "</div>";

            return(new MvcHtmlString(html));
        }
Example #25
0
        //Check Box
        public static MvcHtmlString EAChkBoxP(this HtmlHelper html, string id, string editorClass = "", string label = "")
        {
            var textBoxFor = html.CheckBox(id, new { @class = "form-control form-control-sm" });

            label = TextUnBound(id, label);
            return(new MvcHtmlString(textBoxFor.ToHtmlString()));
        }
Example #26
0
        public static MvcHtmlString EAChkBox(this HtmlHelper html, string id, string editorClass = "", string label = "")
        {
            var textBoxFor = html.CheckBox(id, new { @class = "form-control" });

            label = TextUnBound(id, label);
            return(new MvcHtmlString(FetchStdFormWrappers(textBoxFor, MvcHtmlString.Empty, label, editorClass)));
        }
Example #27
0
        public void CheckboxAddsUnobtrusiveValidationAttributes()
        {
            // Arrange
            const string fieldName            = "name";
            var          modelStateDictionary = new ModelStateDictionary();
            var          validationHelper     = new ValidationHelper(
                new Mock <HttpContextBase>().Object,
                modelStateDictionary
                );
            HtmlHelper helper = HtmlHelperFactory.Create(modelStateDictionary, validationHelper);

            // Act
            validationHelper.RequireField(fieldName, "Please specify a valid Name.");
            validationHelper.Add(
                fieldName,
                Validator.StringLength(30, errorMessage: "Name cannot exceed {0} characters")
                );
            var html = helper.CheckBox(
                fieldName,
                new Dictionary <string, object> {
                { "data-some-val", "5" }
            }
                );

            // Assert
            Assert.Equal(
                @"<input data-some-val=""5"" data-val=""true"" data-val-length=""Name cannot exceed 30 characters"" data-val-length-max=""30"" data-val-required=""Please specify a valid Name."" id=""name"" name=""name"" type=""checkbox"" />",
                html.ToString()
                );
        }
Example #28
0
        private string GenerateCheckBox <TModel>(ControlFormResult <TModel> controlForm, HtmlHelper htmlHelper) where TModel : class
        {
            if (PropertyType != typeof(bool) && PropertyType != typeof(bool?))
            {
                throw new NotSupportedException("Cannot apply control choice for non-Boolean property as checkbox.");
            }

            var attributes = new RouteValueDictionary();

            if (Required)
            {
                attributes.Add("data-val", "true");
                attributes.Add("data-val-required", Constants.Messages.Validation.Required);
            }

            if (!string.IsNullOrEmpty(DataBind))
            {
                attributes.Add("data-bind", DataBind);
            }

            if (!string.IsNullOrEmpty(OnSelectedIndexChanged))
            {
                attributes.Add("onchange", OnSelectedIndexChanged);
            }

            if (ReadOnly || controlForm.ReadOnly)
            {
                attributes.Add("disabled", "disabled");
            }

            var sbCheckBox = new StringBuilder();

            sbCheckBox.AppendFormat("<div class=\"checkbox\"><label class=\"{0}\">", CssClass);

            if (!string.IsNullOrEmpty(PrependText))
            {
                sbCheckBox.Append(PrependText);
                sbCheckBox.Append("&nbsp;");
            }

            var checkBox = htmlHelper.CheckBox(Name, Convert.ToBoolean(Value), attributes);

            sbCheckBox.Append(checkBox);

            if (!string.IsNullOrEmpty(AppendText))
            {
                sbCheckBox.Append("&nbsp;");
                sbCheckBox.Append(AppendText);
            }

            sbCheckBox.Append("</label></div>");

            if (!string.IsNullOrEmpty(HelpText))
            {
                sbCheckBox.AppendFormat("<span class=\"help-block\">{0}</span>", HelpText);
            }

            return(sbCheckBox.ToString());
        }
Example #29
0
 private void WriteSizeCheckbox(HtmlTextWriter writer, Size size)
 {
     writer.AddAttribute(HtmlTextWriterAttribute.Class, "stockCheckbox");
     writer.RenderBeginTag(HtmlTextWriterTag.Div);
     writer.Write(size.Name);
     writer.Write(htmlHelper.CheckBox("stockitem_{0}".With(size.Id), size.IsInStock));
     writer.RenderEndTag();
 }
        public static MvcHtmlString CheckBoxFor <TModel>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, bool?> > expression, IDictionary <string, object> htmlAttributes)
        {
            ModelMetadata modelMeta = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData);
            bool?         value     = (modelMeta.Model as bool?);
            string        name      = ExpressionHelper.GetExpressionText(expression);

            return(htmlHelper.CheckBox(name, value ?? false, htmlAttributes));
        }
        public static string RenderCheckBox(HtmlHelper html, BootstrapCheckBoxModel model)
        {
            if (model.tooltipConfiguration != null) model.htmlAttributes.AddRange(model.tooltipConfiguration.ToDictionary());
            var mergedHtmlAttrs = string.IsNullOrEmpty(model.id) ? model.htmlAttributes : model.htmlAttributes.AddOrReplace("id", model.id);

            string validationMessage = "";
            if (model.displayValidationMessage)
            {
                string validation = html.ValidationMessage(model.htmlFieldName).ToHtmlString();
                validationMessage = new BootstrapHelpText(validation, model.validationMessageStyle).ToHtmlString();
            }
            return html.CheckBox(model.htmlFieldName, model.isChecked, mergedHtmlAttrs.FormatHtmlAttributes()).ToHtmlString() + validationMessage;
        }
 public override MvcHtmlString Generate(HtmlHelper htmlHelper, string name, object value)
 {
     return htmlHelper.CheckBox(name, new { @class = CssClass, style = CssStyle });
 }
Example #33
0
        private static MvcHtmlString CheckBoxForParameter(HtmlHelper htmlHelper, ReportParameter reportParameter, bool disabled)
        {
            bool value;
            if (!bool.TryParse(reportParameter.CurrentValue, out value)) value = false;

            Dictionary<string, object> htmlAttributes = GetHtmlAttributes(reportParameter.Dependents, null, disabled);

            return htmlHelper.CheckBox(reportParameter.Id, value, htmlAttributes);
        }
 public override MvcHtmlString WriteInput(HtmlHelper helper, object htmlAttributes)
 {
     IDictionary<string, object> efHtmlAttributes = new RouteValueDictionary(htmlAttributes);
     AddCommonHtmlAttributes(efHtmlAttributes);
     return helper.CheckBox(this.InputName, this.IsChecked, efHtmlAttributes);
 }
 private static string BooleanTemplateCheckbox(HtmlHelper html, bool value)
 {
     return html.CheckBox(String.Empty, value, CreateHtmlAttributes(html, "check-box")).ToHtmlString();
 }