예제 #1
0
        public static string GetValidateAttr(ValidateOptions validateOptions)
        {
            StringBuilder builder = new StringBuilder();

            builder.Append(validateOptions.Required ? "required," : "");
            builder.Append(validateOptions.StringOnly ? "alpha," : "");
            builder.Append(validateOptions.StringOrNumber ? "alphanum," : "");
            builder.Append(validateOptions.Digit ? "digit," : "");
            builder.Append(validateOptions.Number ? "number," : "");
            builder.Append(validateOptions.Email ? "email," : "");
            builder.Append(validateOptions.Url ? "url," : "");
            builder.Append((validateOptions.Mininum > 0L) ? string.Format("min!{0}!,", validateOptions.Mininum) : "");
            builder.Append((validateOptions.Maxinum > 0L) ? string.Format("max!{0}!,", validateOptions.Maxinum) : "");
            builder.Append((validateOptions.MinLength > 0L) ? string.Format("minlength!{0}!,", validateOptions.MinLength) : "");
            builder.Append((validateOptions.MaxLength > 0L) ? string.Format("maxlength!{0}!,", validateOptions.MaxLength) : "");
            builder.Append(!string.IsNullOrEmpty(validateOptions.RangeLength) ? string.Format("rangelength!{0}!,", validateOptions.RangeLength) : "");
            builder.Append(!string.IsNullOrEmpty(validateOptions.NumberBetween) ? string.Format("between!{0}!,", validateOptions.NumberBetween) : "");
            builder.Append(!string.IsNullOrEmpty(validateOptions.EqualTo) ? string.Format("equalto!{0}!,", validateOptions.EqualTo) : "");
            builder.Append(!string.IsNullOrEmpty(validateOptions.NotEqualTo) ? string.Format("differs!{0}!,", validateOptions.NotEqualTo) : "");
            builder.Append((validateOptions.Length > 0L) ? string.Format("length!{0}!,", validateOptions.Length) : "");
            builder.Append(validateOptions.Mobile ? "mobile," : "");
            return(builder.ToString().TrimEnd(new char[] { ',' }));
        }
        public static MvcHtmlString KingRadioButtonList(this HtmlHelper htmlHelper, string name, Type enumType, string defaultValue = null, ValidateOptions validateOption = null, object htmlAttribute = null, RepeatDirection repeatDirection = 0, bool IsDefaultStyle = true, bool readOnly = false)
        {
            List <SelectListItem> enumToSelectList = MvcHtmlStringCommon.GetEnumToSelectList(enumType);

            return(MvcHtmlString.Create(GenerateHtml(name, enumToSelectList, validateOption, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttribute), repeatDirection, defaultValue, IsDefaultStyle, readOnly) + AddJs(htmlHelper)));
        }
 public static MvcHtmlString KingRadioButtonList(this HtmlHelper htmlHelper, string name, IEnumerable <SelectListItem> dataSource, ValidateOptions validateOption = null, object htmlAttribute = null, RepeatDirection repeatDirection = 0, bool IsDefaultStyle = true, bool readOnly = false)
 {
     return(MvcHtmlString.Create(GenerateHtml(name, dataSource, validateOption, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttribute), repeatDirection, null, IsDefaultStyle, readOnly) + AddJs(htmlHelper)));
 }
        public static string GenerateHtml(string name, IEnumerable <SelectListItem> items, ValidateOptions validateOptions, IDictionary <string, object> htmlAttributes, RepeatDirection repeatDirection = 0, object defaultValue = null, bool IsDefaultStyle = true, bool readOnly = false)
        {
            TagBuilder builder = new TagBuilder("div");

            builder.MergeAttribute("id", name);
            int  num       = 0;
            bool isChecked = false;

            foreach (SelectListItem item in items)
            {
                isChecked = (defaultValue == null) ? item.Selected : (defaultValue.ToString() == item.Value);
                num++;
                string id = string.Format("{0}_{1}", name, num);
                builder.InnerHtml = builder.InnerHtml + GenerateRadioHtml(name, id, item.Text, item.Value, isChecked, htmlAttributes, (num == items.Count <SelectListItem>()) ? validateOptions : null, readOnly);
            }
            if (!IsDefaultStyle)
            {
                builder.InnerHtml = builder.InnerHtml + "<script type='text/javascript'>";
                builder.InnerHtml = builder.InnerHtml + string.Format("$('#{0}').buttonset();", name);
                builder.InnerHtml = builder.InnerHtml + "</script>";
            }
            return(builder.ToString());
        }
예제 #5
0
 public static MvcHtmlString KingDatePicker(this HtmlHelper helper, string name, DateEnum dateEnum, string value = null, ValidateOptions validateOptions = null)
 {
     return(GetDatePickerHtml(helper, name, dateEnum, value, validateOptions));
 }
예제 #6
0
        public static MvcHtmlString KingCheckBoxListFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TValue> > expression, string name = null, object Value = null, ValidateOptions validateOptions = null, bool IsDefaultStyle = true, object htmlAttribute = null, bool readOnly = false)
        {
            ModelMetadata metadata = ModelMetadata.FromLambdaExpression <TModel, TValue>(expression, htmlHelper.ViewData);

            if (string.IsNullOrEmpty(name))
            {
                name = ExpressionHelper.GetExpressionText(expression);
            }
            IEnumerable <SelectListItem> items = null;

            if (Value == null)
            {
                Value = metadata.Model;
            }
            Type modelType = ValidateCommon.GetModelType(metadata.ModelType);

            if (modelType.IsEnum)
            {
                items = new SelectList(MvcHtmlStringCommon.GetEnumToSelectList(modelType).AsEnumerable <SelectListItem>(), "Value", "Text");
            }
            else if (modelType == typeof(bool))
            {
                SelectListItem item = new SelectListItem {
                    Text  = "",
                    Value = "1"
                };
                List <SelectListItem> list = new List <SelectListItem> {
                    item
                };
                if (metadata.Model != null)
                {
                    Value = ((bool)metadata.Model) ? "1" : "0";
                }
                items = new SelectList(list, "Value", "Text");
            }
            return(MvcHtmlString.Create(GenerateHtml(name, items, htmlAttribute, Value, validateOptions, IsDefaultStyle, readOnly) + AddJs(htmlHelper)));
        }
예제 #7
0
 public static MvcHtmlString KingCheckBoxList(this HtmlHelper htmlHelper, string name, IEnumerable <SelectListItem> list, object Value = null, ValidateOptions validateOptions = null, bool IsDefaultStyle = true, object htmlAttribute = null, bool readOnly = false)
 {
     return(MvcHtmlString.Create(GenerateHtml(name, list, htmlAttribute, Value, validateOptions, IsDefaultStyle, readOnly) + AddJs(htmlHelper)));
 }
예제 #8
0
        public static string GenerateCheckBoxHtml(string name, string id, string labelText, string value, bool isChecked, IDictionary <string, object> htmlAttributes, ValidateOptions validateOptions, bool readOnly)
        {
            StringBuilder builder = new StringBuilder();

            builder.AppendLine("<div class='checkbox_label'>");
            TagBuilder builder2 = new TagBuilder("label");

            builder2.MergeAttribute("for", id);
            builder2.SetInnerText(labelText);
            TagBuilder builder3 = new TagBuilder("input");

            builder3.GenerateId(id);
            builder3.MergeAttribute("name", name);
            builder3.MergeAttribute("custom", "big");
            builder3.MergeAttribute("type", "checkbox");
            builder3.MergeAttribute("value", value);
            if (readOnly)
            {
                builder3.MergeAttribute("disabled", "disabled");
            }
            builder3.MergeAttributes <string, object>(htmlAttributes);
            if (readOnly)
            {
                builder3.MergeAttribute("onclick", "return false;");
            }
            if (isChecked)
            {
                builder3.MergeAttribute("checked", "checked");
            }
            if (validateOptions != null)
            {
                builder3.MergeAttribute("data-bvalidator", ValidateCommon.GetValidateAttr(validateOptions));
                if (!string.IsNullOrEmpty(validateOptions.ErrorMsg))
                {
                    builder3.MergeAttribute("data-bvalidator-msg", validateOptions.ErrorMsg);
                }
            }
            builder.AppendLine("<span>" + builder3.ToString() + "</span>");
            builder.AppendLine(builder2.ToString());
            builder.AppendLine("</div>");
            return(builder.ToString());
        }
        public static MvcHtmlString KingComboboxFor <TModel, TValue>(this HtmlHelper <TModel> html, Expression <Func <TModel, TValue> > expression, string name = null, string Value = null, bool IsShowEmptyItem = true, ValidateOptions validateOptions = null, object htmlAttribute = null, string onselect = null)
        {
            ModelMetadata metadata = ModelMetadata.FromLambdaExpression <TModel, TValue>(expression, html.ViewData);

            if (string.IsNullOrEmpty(name))
            {
                name = ExpressionHelper.GetExpressionText(expression);
            }
            if (string.IsNullOrEmpty(Value) && (metadata.Model != null))
            {
                Value = metadata.Model.ToString();
            }
            IEnumerable <SelectListItem> list = null;
            Type modelType = ValidateCommon.GetModelType(metadata.ModelType);

            if (modelType.IsEnum)
            {
                list = MvcHtmlStringCommon.GetEnumToSelectList(modelType);
            }
            else if (modelType == typeof(bool))
            {
                SelectListItem item = new SelectListItem {
                    Value = "1",
                    Text  = "是"
                };
                SelectListItem item2 = new SelectListItem {
                    Value = "0",
                    Text  = "否"
                };
                list = new List <SelectListItem> {
                    item,
                    item2
                };
            }
            return(MvcHtmlString.Create(GetSelect(html, name, Value, IsShowEmptyItem, htmlAttribute, list, validateOptions, onselect) + AddJs <TModel, TValue>(html)));
        }
        public static MvcHtmlString KingCombobox(this HtmlHelper html, string name, Type enumType, string Value = null, bool IsShowEmptyItem = true, ValidateOptions validateOptions = null, object htmlAttribute = null, string onselect = null)
        {
            List <SelectListItem> enumToSelectList = MvcHtmlStringCommon.GetEnumToSelectList(enumType);

            return(MvcHtmlString.Create(GetSelect(html, name, Value, IsShowEmptyItem, htmlAttribute, enumToSelectList, validateOptions, onselect) + AddJs(html)));
        }
 public static MvcHtmlString KingCombobox(this HtmlHelper html, string name, IEnumerable <SelectListItem> list, string Value = null, bool IsShowEmptyItem = true, ValidateOptions validateOptions = null, object htmlAttribute = null, string onselect = null)
 {
     return(MvcHtmlString.Create(GetSelect(html, name, Value, IsShowEmptyItem, htmlAttribute, list, validateOptions, onselect) + AddJs(html)));
 }
        private static string GetSelect(HtmlHelper html, string name, string Value, bool IsShowEmptyItem, object htmlAttribute, IEnumerable <SelectListItem> list, ValidateOptions validateOptions, string onselect)
        {
            TagBuilder    builder2;
            ComboboxModel model = new ComboboxModel {
                Name         = name.Replace(".", "_"),
                SelectedFunc = (onselect == null) ? "" : onselect
            };

            html.RenderPartial("~/Views/ControlScripts/_ComboboxScripts.cshtml", model);
            TagBuilder builder = new TagBuilder("select");

            builder.GenerateId(name);
            builder.MergeAttribute("name", name);
            builder.MergeAttributes <string, object>(HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttribute));
            if (validateOptions != null)
            {
                builder.MergeAttribute("data-bvalidator", ValidateCommon.GetValidateAttr(validateOptions));
                if (!string.IsNullOrEmpty(validateOptions.ErrorMsg))
                {
                    builder.MergeAttribute("data-bvalidator-msg", validateOptions.ErrorMsg);
                }
            }
            if (IsShowEmptyItem)
            {
                builder2 = new TagBuilder("option");
                if (string.IsNullOrEmpty(Value))
                {
                    builder2.MergeAttribute("selected", "selected");
                }
                builder2.MergeAttribute("value", " ");
                builder2.SetInnerText("--请选择--");
                builder.InnerHtml = builder.InnerHtml + builder2.ToString();
            }
            foreach (SelectListItem item in list)
            {
                builder2 = new TagBuilder("option");
                builder2.MergeAttribute("value", item.Value);
                builder2.SetInnerText(item.Text);
                if (string.IsNullOrEmpty(Value) && item.Selected)
                {
                    Value = item.Value;
                }
                if (item.Value == Value)
                {
                    builder2.MergeAttribute("selected", "selected");
                }
                builder.InnerHtml = builder.InnerHtml + builder2.ToString();
            }
            bool flag = false;

            if ((validateOptions != null) && validateOptions.Required)
            {
                flag = true;
            }
            return((flag ? "<span class='star'>*</span>" : "<span class='star'>&nbsp</span>") + builder.ToString());
        }
        private static MvcHtmlString GetSelectUserHtml(HtmlHelper html, string name, List <ITreeData> data, string GetLeafURL, string CallBackMethod, UserStyle userStyle, OpenNoteEnum openNote, ValidateOptions validateOptions, string value)
        {
            BizDataContext       context;
            List <string>        keyList    = new List <string>();
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            StringBuilder        builder    = new StringBuilder();
            TagBuilder           builder2   = new TagBuilder("div");

            builder2.GenerateId(name);
            builder2.AddCssClass("treeDiv");
            TagBuilder builder3 = GetTagBuilder("ul", name, "ztree");

            builder3.MergeAttribute("style", "display : none;");
            builder2.InnerHtml = builder2.InnerHtml + builder3;
            TagBuilder builder4 = GetTagBuilder("div", name, "dataHF");

            builder4.MergeAttribute("style", "display:none;");
            if ((data != null) && (data.Count > 0))
            {
                data = DealWithNoteOpenState(data, openNote);
                builder4.InnerHtml = builder4.InnerHtml + serializer.Serialize(data);
            }
            else
            {
                using (context = new BizDataContext(true))
                {
                    ParameterExpression expression;
                    // List<ITreeData> list2 = DealWithNoteOpenState(context.Set<T_Department>().
                    //    Select<T_Department, TreeData>(Expression.Lambda<Func<T_Department, TreeData>>(Expression.MemberInit(Expression.New((ConstructorInfo) methodof(TreeData..ctor), new Expression[0]), new MemberBinding[] { Expression.Bind((MethodInfo) methodof(TreeData.set_id), Expression.Property(expression = Expression.Parameter(typeof(T_Department), "u"), (MethodInfo) methodof(T_Department.get_Department_ID))), Expression.Bind((MethodInfo) methodof(TreeData.set_name), Expression.Property(expression, (MethodInfo) methodof(T_Department.get_Department_Name))), Expression.Bind((MethodInfo) methodof(TreeData.set_open), Expression.Constant(false, typeof(bool))), Expression.Bind((MethodInfo) methodof(TreeData.set_pId), Expression.Coalesce(Expression.Property(expression, (MethodInfo) methodof(T_Department.get_Parent_ID)), Expression.Constant(-1, typeof(int)))) }), new ParameterExpression[] { expression })).ToList<ITreeData>(), openNote);
                    //builder4.InnerHtml = builder4.InnerHtml + serializer.Serialize(list2);
                }
            }
            builder2.InnerHtml = builder2.InnerHtml + builder4;
            TagBuilder builder5 = GetTagBuilder("input", name, "resultInput");

            if (userStyle == UserStyle.Normal)
            {
                builder5.MergeAttribute("style", "float: left;");
            }
            else
            {
                builder5.MergeAttribute("style", "float: left;display:none");
            }
            builder5.MergeAttribute("type", "text");
            if (validateOptions != null)
            {
                builder5.MergeAttribute("data-bvalidator", ValidateCommon.GetValidateAttr(validateOptions));
                if (!string.IsNullOrEmpty(validateOptions.ErrorMsg))
                {
                    builder5.MergeAttribute("data-bvalidator-msg", validateOptions.ErrorMsg);
                }
            }
            builder5.MergeAttribute("readonly", "true");
            TagBuilder builder6 = GetTagBuilder("input", name, "resultHf");

            builder6.MergeAttribute("type", "hidden");
            builder2.InnerHtml = builder2.InnerHtml + builder5;
            builder2.InnerHtml = builder2.InnerHtml + builder6;
            TagBuilder builder7 = GetTagBuilder("input", name, "treeButton");

            builder7.MergeAttribute("type", "button");
            builder7.MergeAttribute("value", "选择");
            builder7.MergeAttribute("treeName", name);
            builder2.InnerHtml = builder2.InnerHtml + builder7;
            TagBuilder builder8 = GetTagBuilder("input", name, "selectedIDHf");

            builder8.MergeAttribute("type", "hidden");
            string str = string.Empty;

            if (!string.IsNullOrEmpty(value))
            {
                string[] strArray = value.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                using (context = new BizDataContext(true))
                {
                    IEnumerable <string> values = from u in context.FetchAll <T_User>()
                                                  join suid in strArray on u.User_ID.ToString() equals suid
                                                  select u.User_Name;

                    str = string.Join(",", values);
                }
                builder8.MergeAttribute("value", value);
            }
            builder2.InnerHtml = builder2.InnerHtml + builder8;
            TagBuilder builder9 = GetTagBuilder("input", name, "selectedNameHF");

            builder9.MergeAttribute("type", "hidden");
            builder9.MergeAttribute("value", str);
            builder2.InnerHtml = builder2.InnerHtml + builder9;
            TagBuilder builder10 = GetTagBuilder("input", name, "configDataHF");

            builder10.MergeAttribute("type", "hidden");
            Dictionary <string, string> dictionary = new Dictionary <string, string>();

            dictionary.Add("GetLeafURL", GetLeafURL);
            dictionary.Add("CallBackMethod", CallBackMethod);
            builder10.MergeAttribute("value", serializer.Serialize(dictionary));
            builder2.InnerHtml = builder2.InnerHtml + builder10;
            builder.AppendLine(builder2.ToString());
            builder.AppendLine(CtrlScripts.RenderScript(html, keyList));
            return(MvcHtmlString.Create(builder.ToString()));
        }
예제 #14
0
        private static MvcHtmlString GetDatePickerHtml(HtmlHelper html, string name, DateEnum dateEnum, string value, ValidateOptions validateOptions)
        {
            DatePicketModel model = new DatePicketModel {
                Name     = name,
                DateType = dateEnum
            };

            html.RenderPartial("~/Views/ControlScripts/_DatePicketScripts.cshtml", model);
            List <string> keyList  = new List <string>();
            StringBuilder builder  = new StringBuilder();
            TagBuilder    builder2 = new TagBuilder("input");

            builder2.GenerateId(name);
            builder2.MergeAttribute("type", "text");
            builder2.MergeAttribute("name", name);
            builder2.MergeAttribute("readonly", "readonly");
            if (!string.IsNullOrEmpty(value))
            {
                builder2.MergeAttribute("value", value);
            }
            bool flag = false;

            if (validateOptions != null)
            {
                builder2.MergeAttribute("data-bvalidator", ValidateCommon.GetValidateAttr(validateOptions));
                if (validateOptions.Required)
                {
                    flag = true;
                }
                if (!string.IsNullOrEmpty(validateOptions.ErrorMsg))
                {
                    builder2.MergeAttribute("data-bvalidator-msg", validateOptions.ErrorMsg);
                }
            }
            builder.AppendLine(builder2.ToString());
            builder.AppendLine(CtrlScripts.RenderScript(html, keyList));
            return(MvcHtmlString.Create((flag ? "<span class='star'>*</span>" : "<span class='star'>&nbsp</span>") + builder.ToString()));
        }
예제 #15
0
        public static MvcHtmlString KingDatePickerFor <TModel, TProperty>(this HtmlHelper <TModel> helper, Expression <Func <TModel, TProperty> > expression, DateEnum dateEnum, string value = null, ValidateOptions validateOptions = null)
        {
            ModelMetadata metadata       = ModelMetadata.FromLambdaExpression <TModel, TProperty>(expression, helper.ViewData);
            string        expressionText = ExpressionHelper.GetExpressionText(expression);

            if (metadata.Model != null)
            {
                DateTime time = Convert.ToDateTime(metadata.Model);
                value = (dateEnum == DateEnum.DateTime) ? time.ToString("yyyy-MM-dd HH:mm:ss") : time.ToString("yyyy-MM-dd");
            }
            return(GetDatePickerHtml(helper, expressionText, dateEnum, value, validateOptions));
        }
        public static MvcHtmlString KingRadioButtonListFor <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, string name, ValidateOptions validateOption = null, RepeatDirection repeatDirection = 0, object htmlAttributes = null, bool IsDefaultStyle = true, bool readOnly = false)
        {
            ModelMetadata metadata       = ModelMetadata.FromLambdaExpression <TModel, TProperty>(expression, htmlHelper.ViewData);
            string        expressionText = ExpressionHelper.GetExpressionText(expression);
            IDictionary <string, object> unobtrusiveValidationAttributes = htmlHelper.GetUnobtrusiveValidationAttributes(expressionText, metadata);
            string fullHtmlFieldName           = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(expressionText);
            IEnumerable <SelectListItem> items = null;
            string defaultValue = "";
            Type   modelType    = ValidateCommon.GetModelType(metadata.ModelType);

            if (modelType.IsEnum)
            {
                items = new SelectList(MvcHtmlStringCommon.GetEnumToSelectList(modelType).AsEnumerable <SelectListItem>(), "Value", "Text");
            }
            else if (modelType == typeof(bool))
            {
                if (metadata.Model != null)
                {
                    defaultValue = ((bool)metadata.Model) ? "1" : "0";
                }
                else
                {
                    defaultValue = "0";
                }
                SelectListItem item = new SelectListItem {
                    Value = "1",
                    Text  = "是"
                };
                SelectListItem item2 = new SelectListItem {
                    Value = "0",
                    Text  = "否"
                };
                items = new List <SelectListItem> {
                    item,
                    item2
                };
            }
            return(MvcHtmlString.Create(GenerateHtml(name, items, validateOption, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes), repeatDirection, defaultValue, IsDefaultStyle, readOnly) + AddJs(htmlHelper)));
        }
        public static MvcHtmlString KingRadioButtonListFor <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, string name, IEnumerable <SelectListItem> dataScource, ValidateOptions validateOption = null, RepeatDirection repeatDirection = 0, object htmlAttributes = null, bool IsDefaultStyle = true, bool readOnly = false)
        {
            ModelMetadata metadata       = ModelMetadata.FromLambdaExpression <TModel, TProperty>(expression, htmlHelper.ViewData);
            string        expressionText = ExpressionHelper.GetExpressionText(expression);
            IDictionary <string, object> unobtrusiveValidationAttributes = htmlHelper.GetUnobtrusiveValidationAttributes(expressionText, metadata);
            string fullHtmlFieldName = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(expressionText);
            string defaultValue      = "";

            if (ValidateCommon.GetModelType(metadata.ModelType) == typeof(bool))
            {
                if (metadata.Model != null)
                {
                    defaultValue = ((bool)metadata.Model) ? "1" : "0";
                }
                else
                {
                    defaultValue = "0";
                }
            }
            else
            {
                defaultValue = (metadata.Model == null) ? "" : metadata.Model.ToString();
            }
            return(MvcHtmlString.Create(GenerateHtml(name, dataScource, validateOption, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes), repeatDirection, defaultValue, IsDefaultStyle, readOnly) + AddJs(htmlHelper)));
        }
        public static MvcHtmlString KingComboboxFor <TModel, TValue>(this HtmlHelper <TModel> html, Expression <Func <TModel, TValue> > expression, Type enumType, string name = null, string Value = null, bool IsShowEmptyItem = true, ValidateOptions validateOptions = null, object htmlAttribute = null, string onselect = null)
        {
            ModelMetadata metadata = ModelMetadata.FromLambdaExpression <TModel, TValue>(expression, html.ViewData);

            if (string.IsNullOrEmpty(name))
            {
                name = ExpressionHelper.GetExpressionText(expression);
            }
            if (string.IsNullOrEmpty(Value) && (metadata.Model != null))
            {
                Value = metadata.Model.ToString();
            }
            IEnumerable <SelectListItem> list = null;

            if (enumType != null)
            {
                list = MvcHtmlStringCommon.GetEnumToSelectList(enumType);
            }
            return(MvcHtmlString.Create(GetSelect(html, name, Value, IsShowEmptyItem, htmlAttribute, list, validateOptions, onselect) + AddJs <TModel, TValue>(html)));
        }
예제 #19
0
        public static string GenerateHtml(string name, IEnumerable <SelectListItem> items, object htmlAttribute, object Value, ValidateOptions validateOptions, bool IsDefaultStyle, bool readOnly)
        {
            TagBuilder builder = new TagBuilder("div");

            builder.MergeAttribute("id", name);
            int  num       = 0;
            bool isChecked = false;

            if (items == null)
            {
                return("");
            }
            foreach (SelectListItem item in items)
            {
                IEnumerable <string> source = Value as IEnumerable <string>;
                isChecked = (source != null) && source.Contains <string>(item.Value);
                if (!(isChecked || (Value == null)))
                {
                    isChecked = Value.ToString() == item.Value;
                }
                num++;
                string id = string.Format("{0}_{1}", name, num);
                builder.InnerHtml = builder.InnerHtml + GenerateCheckBoxHtml(name, id, item.Text, item.Value, isChecked, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttribute), (num == items.Count <SelectListItem>()) ? validateOptions : null, readOnly);
            }
            if (!IsDefaultStyle)
            {
                builder.InnerHtml = builder.InnerHtml + "<script type='text/javascript'>";
                builder.InnerHtml = builder.InnerHtml + string.Format("$('#{0}').buttonset();", name);
                builder.InnerHtml = builder.InnerHtml + "</script>";
            }
            return(builder.ToString());
        }
 public static MvcHtmlString KingTextBox(this HtmlHelper helper, string name, string value = null, object htmlAttribute = null, ValidateOptions validateOptions = null, bool readOnly = false)
 {
     return(MvcHtmlString.Create(GetTextBoxMvcHtml(name, value, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttribute), validateOptions, readOnly) + AddJs(helper)));
 }
예제 #21
0
        public static MvcHtmlString KingCheckBoxList(this HtmlHelper htmlHelper, string name, Type enumType, object Value = null, ValidateOptions validateOptions = null, bool IsDefaultStyle = true, object htmlAttribute = null, bool readOnly = false)
        {
            IEnumerable <SelectListItem> items = new SelectList(MvcHtmlStringCommon.GetEnumToSelectList(enumType).AsEnumerable <SelectListItem>(), "Value", "Text");

            return(MvcHtmlString.Create(GenerateHtml(name, items, htmlAttribute, Value, validateOptions, IsDefaultStyle, readOnly) + AddJs(htmlHelper)));
        }
        public static MvcHtmlString KingTextBoxFor <TModel, TProperty>(this HtmlHelper <TModel> helper, Expression <Func <TModel, TProperty> > expression, object htmlAttribute = null, ValidateOptions validateOptions = null, bool readOnly = false)
        {
            ModelMetadata metadata       = ModelMetadata.FromLambdaExpression <TModel, TProperty>(expression, helper.ViewData);
            string        expressionText = ExpressionHelper.GetExpressionText(expression);
            string        str2           = (metadata.Model == null) ? "" : metadata.Model.ToString();

            return(MvcHtmlString.Create(GetTextBoxMvcHtml(expressionText, str2, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttribute), validateOptions, readOnly) + AddJs(helper)));
        }
예제 #23
0
        public static MvcHtmlString KingCheckBoxListFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TValue> > expression, Type enumType, string name = null, object Value = null, ValidateOptions validateOptions = null, bool IsDefaultStyle = true, object htmlAttribute = null, bool readOnly = false)
        {
            IEnumerable <SelectListItem> items = new SelectList(MvcHtmlStringCommon.GetEnumToSelectList(enumType).AsEnumerable <SelectListItem>(), "Value", "Text");
            ModelMetadata metadata             = ModelMetadata.FromLambdaExpression <TModel, TValue>(expression, htmlHelper.ViewData);

            if (string.IsNullOrEmpty(name))
            {
                name = ExpressionHelper.GetExpressionText(expression);
            }
            if (Value == null)
            {
                Value = metadata.Model;
            }
            return(MvcHtmlString.Create(GenerateHtml(name, items, htmlAttribute, Value, validateOptions, IsDefaultStyle, readOnly) + AddJs(htmlHelper)));
        }
        private static string GetTextBoxMvcHtml(string name, string value, IDictionary <string, object> htmlAttribute, ValidateOptions validateOptions, bool readOnly)
        {
            TagBuilder builder = new TagBuilder("input");

            builder.GenerateId(name);
            builder.MergeAttribute("name", name);
            builder.MergeAttribute("type", "text");
            if (!string.IsNullOrEmpty(value))
            {
                builder.MergeAttribute("value", value);
            }
            if (readOnly)
            {
                builder.MergeAttribute("readonly", "readonly");
                string str = string.Empty;
                if ((htmlAttribute != null) && (htmlAttribute.Count > 0))
                {
                    if (htmlAttribute.ContainsKey("style"))
                    {
                        object obj2 = null;
                        if (htmlAttribute.TryGetValue("style", out obj2))
                        {
                            str = obj2.ToString().TrimEnd(new char[] { ';' });
                        }
                        str = str + ";background-color: #DFDFDF;";
                        htmlAttribute.Remove("style");
                        htmlAttribute.Add("style", str);
                    }
                    else
                    {
                        htmlAttribute.Add("style", "background-color: #DFDFDF");
                    }
                }
                else
                {
                    htmlAttribute.Add("style", "background-color: #DFDFDF");
                }
            }
            builder.MergeAttributes <string, object>(htmlAttribute);
            bool flag = false;

            if (validateOptions != null)
            {
                builder.MergeAttribute("data-bvalidator", ValidateCommon.GetValidateAttr(validateOptions));
                if (validateOptions.Required)
                {
                    flag = true;
                }
                if (!string.IsNullOrEmpty(validateOptions.ErrorMsg))
                {
                    builder.MergeAttribute("data-bvalidator-msg", validateOptions.ErrorMsg);
                }
            }
            return((flag ? "<span class='star'>*</span>" : "<span class='star'>&nbsp</span>") + builder.ToString());
        }