public static MvcHtmlString KingRadioButtonListFor <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, string name, Type enumType, string defaultValue = null, ValidateOptions validateOption = null, RepeatDirection repeatDirection = 0, object htmlAttribute = 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 str3 = "";

            if (ValidateCommon.GetModelType(metadata.ModelType) == typeof(bool))
            {
                if (metadata.Model != null)
                {
                    str3 = ((bool)metadata.Model) ? "1" : "0";
                }
                else
                {
                    str3 = "0";
                }
            }
            else
            {
                str3 = (metadata.Model == null) ? "" : metadata.Model.ToString();
            }
            defaultValue = string.IsNullOrEmpty(str3) ? defaultValue : str3;
            List <SelectListItem> enumToSelectList = MvcHtmlStringCommon.GetEnumToSelectList(enumType);

            return(MvcHtmlString.Create(GenerateHtml(name, enumToSelectList, validateOption, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttribute), repeatDirection, defaultValue, IsDefaultStyle, readOnly) + AddJs(htmlHelper)));
        }
Ejemplo n.º 2
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)));
        }
        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)));
        }
        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)));
        }
Ejemplo n.º 5
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)));
        }
        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)));
        }
Ejemplo n.º 7
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 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 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)));
        }