Ejemplo n.º 1
0
        public static MvcHtmlString DropDownList(this HtmlHelper helper, string name, Type type, object selectedValue, object htmlAttributes)
        {
            if (!type.IsEnum)
            {
                throw new ArgumentException("Invalid type. It should be an enum.");
            }
            if (selectedValue == null || selectedValue.GetType() != type)
            {
                throw new ArgumentException("Invalid selected value type. It should be '" + type.ToString() + "'");
            }

            var items = new List <SelectListItem>();

            foreach (int value in Enum.GetValues(type))
            {
                string valueText = Enum.GetName(type, value);
                if (!IsObsoleteValue(value, valueText, type))
                {
                    var item = new SelectListItem();
                    item.Value    = value.ToString();
                    item.Text     = valueText;
                    item.Selected = object.Equals(value, (int)selectedValue);
                    items.Add(item);
                }
            }
            return(SelectExtensions.DropDownList(helper, name, items, htmlAttributes));
        }
        public static MvcHtmlString DropDownListFor <TModel, TListItemType, TItemId, TItemName, TSelectedValue>(
            this HtmlHelper <TModel> htmlHelper,
            Expression <Func <TModel, TSelectedValue> > formFieldName,
            Expression <Func <TModel, ICollection <TListItemType> > > items,
            Expression <Func <TListItemType, TItemId> > optionValueProperty,
            Expression <Func <TListItemType, TItemName> > optionInnerHtmlProperty,
            [Optional] string optionLabel,
            [Optional] object htmlAttributes)
        {
            if (htmlHelper == null)
            {
                throw new ArgumentNullException(paramName: "htmlHelper", message: "The static Html Helper is null.");
            }

            var formField            = ExpressionHelper.GetExpressionText(formFieldName);
            var itemIdPropertyName   = ExpressionHelper.GetExpressionText(optionValueProperty);
            var itemNamePropertyName = ExpressionHelper.GetExpressionText(optionInnerHtmlProperty);

            var listItemsModel = GetModelFromExpressionAndViewData(items, htmlHelper.ViewData) as List <TListItemType>;

            // if the list is null, initialize to an empty list so we display something
            if (listItemsModel == null)
            {
                listItemsModel = new List <TListItemType>();
            }

            var selectedValueObject = GetModelFromExpressionAndViewData(formFieldName, htmlHelper.ViewData);

            var selectList = new SelectList(listItemsModel, itemIdPropertyName, itemNamePropertyName, selectedValueObject);

            return(SelectExtensions.DropDownList(htmlHelper: htmlHelper, name: formField, selectList: selectList, optionLabel: optionLabel, htmlAttributes: htmlAttributes));
        }
        public static MvcHtmlString DropDownListBind(this HtmlHelper htmlHelper, string name, IEnumerable <SelectListItem> selectList, string optionLabel, object htmlAttributes)
        {
            var bind = new KnockoutBind(null, htmlAttributes);

            bind.AddBind("value", name);
            return(SelectExtensions.DropDownList(htmlHelper, name, selectList, optionLabel, bind));
        }
        //https://jeremylindsayni.wordpress.com/2015/01/17/mvc-enhanced-dropdownlistfor-part-2/

        /// <summary>
        /// Returns a single-selection HTML &lt;select&gt; element for the expression <paramref name="name" />,
        /// using the specified list items.
        /// </summary>
        /// <typeparam name="TModel">The type of the model.</typeparam>
        /// <typeparam name="TListItemType">The type of the items in the list.</typeparam>
        /// <typeparam name="TItemId">The type of the item identifier.</typeparam>
        /// <typeparam name="TItemName">The type of the item name.</typeparam>
        /// <typeparam name="TSelectedValue">The type of the selected value expression result.</typeparam>
        /// <param name="htmlHelper">The HTML helper instance that this method extends.</param>
        /// <param name="formFieldName">Name of the form field.</param>
        /// <param name="items">The items to put in the  HTML &lt;select&gt; element.</param>
        /// <param name="optionValueProperty">The item identifier property.</param>
        /// <param name="optionInnerHTMLProperty">The item name property.</param>
        /// <param name="optionLabel">The text for a default empty item. Does not include such an item if argument is <c>null</c>.</param>
        /// <param name="htmlAttributes">An <see cref="object" /> that contains the HTML attributes for the &lt;select&gt; element. Alternatively, an
        /// <see cref="IDictionary{string, object}" /> instance containing the HTML attributes.</param>
        /// <returns>A new MvcHtmlString containing the &lt;select&gt; element.</returns>
        public static MvcHtmlString AutoDropDownListFor <TModel, TListItemType, TItemId, TItemName, TSelectedValue>(
            this HtmlHelper <TModel> htmlHelper,
            Expression <Func <TModel, TSelectedValue> > formFieldName,
            Expression <Func <TModel, List <TListItemType> > > items,
            Expression <Func <TListItemType, TItemId> > optionValueProperty,
            Expression <Func <TListItemType, TItemName> > optionInnerHTMLProperty,
            string optionLabel    = null,
            object htmlAttributes = null)
        {
            var formField            = ExpressionHelper.GetExpressionText(formFieldName);
            var itemIdPropertyName   = ExpressionHelper.GetExpressionText(optionValueProperty);
            var itemNamePropertyName = ExpressionHelper.GetExpressionText(optionInnerHTMLProperty);

            var listItemsModel = GetModelFromExpressionAndViewData(items, htmlHelper.ViewData) as List <TListItemType>;

            // if the list is null, initialize to an empty list so we display something
            if (listItemsModel == null)
            {
                listItemsModel = new List <TListItemType>();
            }

            var selectedValueObject = GetModelFromExpressionAndViewData(formFieldName, htmlHelper.ViewData);

            var selectList = new SelectList(listItemsModel, itemIdPropertyName, itemNamePropertyName, selectedValueObject);

            return(SelectExtensions.DropDownList(htmlHelper: htmlHelper, name: formField, selectList: selectList, optionLabel: optionLabel, htmlAttributes: htmlAttributes));
        }
Ejemplo n.º 5
0
        public static MvcHtmlString TimeDropDownList(this HtmlHelper html, string name, object htmlAttributes, int selectedHr = 0)
        {
            var list = new SelectList(new[]
            {
                new { Key = "0", Value = "00:00" },
                new { Key = "1", Value = "01:00" },
                new { Key = "2", Value = "02:00" },
                new { Key = "3", Value = "03:00" },
                new { Key = "4", Value = "04:00" },
                new { Key = "5", Value = "05:00" },
                new { Key = "6", Value = "06:00" },
                new { Key = "7", Value = "07:00" },
                new { Key = "8", Value = "08:00" },
                new { Key = "9", Value = "09:00" },
                new { Key = "10", Value = "10:00" },
                new { Key = "11", Value = "11:00" },
                new { Key = "12", Value = "12:00" },
                new { Key = "13", Value = "13:00" },
                new { Key = "14", Value = "14:00" },
                new { Key = "15", Value = "15:00" },
                new { Key = "16", Value = "16:00" },
                new { Key = "17", Value = "17:00" },
                new { Key = "18", Value = "18:00" },
                new { Key = "19", Value = "19:00" },
                new { Key = "20", Value = "20:00" },
                new { Key = "21", Value = "21:00" },
                new { Key = "22", Value = "22:00" },
                new { Key = "23", Value = "23:00" },
                new { Key = "24", Value = "24:00" },
            }, "Key", "Value", selectedHr);

            return(SelectExtensions.DropDownList(html, name, list, htmlAttributes));
        }
Ejemplo n.º 6
0
        public static MvcHtmlString UomEnumDropdownList <TModel, TEnum>(
            this HtmlHelper <TModel> htmlHelper, string name, TEnum selectedValue, object htmlAttributes) where TEnum : struct
        {
            var values = Enum.GetValues(typeof(TEnum)).Cast <TEnum>();
            IEnumerable <SelectListItem> items = ValueToListItems(selectedValue, values);

            return(SelectExtensions.DropDownList(htmlHelper, name, items, htmlAttributes));
        }
Ejemplo n.º 7
0
        public static MvcHtmlString Ul <T>(this HtmlHelper helper, string id, string cssClass, string alternateText, object htmlAttributes, string itemCssClass, IList <T> items, Func <T, IHtmlString> itemContent)
        {
//			// Create tag builder
//			var imgTag = new TagBuilder("img");
//
//			// Create valid id
//			imgTag.GenerateId(id);
//
//			// Add attributes
//			imgTag.MergeAttribute("src", helper.Url().Content(src));
//			imgTag.MergeAttribute("alt", helper.Encode(alternateText));
//			imgTag.MergeAttributes(new RouteValueDictionary(htmlAttributes), true);
//
//			// Render tag
//			return new MvcHtmlString(imgTag.ToString(TagRenderMode.Normal));
            SelectExtensions.DropDownList()
            helper.DropDownList().
            var ulTag = new TagBuilder("ul");

            ulTag.GenerateId(id);
            ulTag.AddCssClass(cssClass);
            ulTag.MergeAttributes(new RouteValueDictionary(htmlAttributes), true);
            var itemNumber = 0;

            foreach (T item in items)
            {
                itemNumber++;
                var liTag = new TagBuilder("li");
                liTag.AddCssClass(itemCssClass);
                if (Menu.IsSelected(item))
                {
                    liTag.AddCssClass(SelectedItemCssClass);
                }
                if (itemNumber == 1)
                {
                    liTag.AddCssClass("first");
                }
                if (itemNumber == items.Count)
                {
                    liTag.AddCssClass("last");
                }
                liTag.InnerHtml = itemContent(item).ToHtmlString();

                //if (string.IsNullOrEmpty(item.ClientCallbackMethod))
                //{
                //    liTag.InnerHtml = System.Web.Mvc.Html.LinkExtensions.ActionLink(Helper, item.Text, item.Url.ActionName, item.Url.ControllerName ?? string.Empty).ToHtmlString();
                //}
                //else
                //{
                //    // see http://stackoverflow.com/questions/134845/href-tag-for-javascript-links-or-javascriptvoid0
                //    liTag.InnerHtml = string.Format("<a onclick=\"{1}\">{0}</a>", item.Text, item.ClientCallbackMethod);
                //}

                ulTag.InnerHtml += liTag.ToString();
            }
            return(MvcHtmlString.Create(ulTag.ToString(TagRenderMode.Normal)));
        }
Ejemplo n.º 8
0
 public static MvcHtmlString DropDownList(this HtmlHelper htmlHelper, string name, IEnumerable <SelectListItem> selectList = null, string optionLabel = null, string cssClass = null, string dir = null, bool disabled = false, string id = null, string lang = null, int?size = null, string style = null, int?tabIndex = null, string title = null)
 {
     return(SelectExtensions.DropDownList(
                htmlHelper,
                name,
                selectList,
                optionLabel,
                SelectAttributes(cssClass, dir, disabled, id, lang, size, style, tabIndex, title)
                ));
 }
Ejemplo n.º 9
0
        public static MvcHtmlString UomEnumDropdownList <TModel, TEnum>(
            this HtmlHelper <TModel> htmlHelper, string name, TEnum?selectedValue, object htmlAttributes) where TEnum : struct
        {
            var stringified = selectedValue != null?selectedValue.Value.ToString() : null;

            var values = new[] { "---" }.Concat(Enum.GetValues(typeof(TEnum)).Cast <TEnum>().Select(v => v.ToString()));
            IEnumerable <SelectListItem> items = ValueToListItems(stringified, values);

            return(SelectExtensions.DropDownList(htmlHelper, name, items, htmlAttributes));
        }
Ejemplo n.º 10
0
        public static MvcHtmlString IconDropDownList(this HtmlHelper html, string name, object htmlAttributes, int selectedIcon = 0)
        {
            string[] arr = new string[] { "fa-adjust", "fa-adn", "fa-align-center", "fa-align-justify", "fa-align-left", "fa-align-right", "fa-ambulance", "fa-anchor", "fa-android", "fa-angle-double-down", "fa-angle-double-left", "fa-angle-double-right", "fa-angle-double-up", "fa-angle-down", "fa-angle-left", "fa-angle-right", "fa-angle-up", "fa-apple", "fa-archive", "fa-arrow-circle-down", "fa-arrow-circle-left", "fa-arrow-circle-o-down", "fa-arrow-circle-o-left", "fa-arrow-circle-o-right", "fa-arrow-circle-o-up", "fa-arrow-circle-right", "fa-arrow-circle-up", "fa-arrow-down", "fa-arrow-left", "fa-arrow-right", "fa-arrow-up", "fa-arrows", "fa-arrows-alt", "fa-arrows-h", "fa-arrows-v", "fa-asterisk", "fa-backward", "fa-ban", "fa-bar-chart-o", "fa-barcode", "fa-bars", "fa-beer", "fa-bell", "fa-bell-o", "fa-bitbucket", "fa-bitbucket-square", "fa-bitcoin", "fa-bold", "fa-bolt", "fa-book", "fa-bookmark", "fa-bookmark-o", "fa-briefcase", "fa-btc", "fa-bug", "fa-building-o", "fa-bullhorn", "fa-bullseye", "fa-calendar", "fa-calendar-o", "fa-camera", "fa-camera-retro", "fa-caret-down", "fa-caret-left", "fa-caret-right", "fa-caret-square-o-down", "fa-caret-square-o-left", "fa-caret-square-o-right", "fa-caret-square-o-up", "fa-caret-up", "fa-certificate", "fa-chain", "fa-chain-broken", "fa-check", "fa-check-circle", "fa-check-circle-o", "fa-check-square", "fa-check-square-o", "fa-chevron-circle-down", "fa-chevron-circle-left", "fa-chevron-circle-right", "fa-chevron-circle-up", "fa-chevron-down", "fa-chevron-left", "fa-chevron-right", "fa-chevron-up", "fa-circle", "fa-circle-o", "fa-clipboard", "fa-clock-o", "fa-cloud", "fa-cloud-download", "fa-cloud-upload", "fa-cny", "fa-code", "fa-code-fork", "fa-coffee", "fa-cog", "fa-cogs", "fa-columns", "fa-comment", "fa-comment-o", "fa-comments", "fa-comments-o", "fa-compass", "fa-compress", "fa-copy", "fa-credit-card", "fa-crop", "fa-crosshairs", "fa-css3", "fa-cut", "fa-cutlery", "fa-dashboard", "fa-dedent", "fa-desktop", "fa-dollar", "fa-dot-circle-o", "fa-download", "fa-dribbble", "fa-dropbox", "fa-edit", "fa-eject", "fa-ellipsis-h", "fa-ellipsis-v", "fa-envelope", "fa-envelope-o", "fa-eraser", "fa-eur", "fa-euro", "fa-exchange", "fa-exclamation", "fa-exclamation-circle", "fa-exclamation-triangle", "fa-expand", "fa-external-link", "fa-external-link-square", "fa-eye", "fa-eye-slash", "fa-facebook", "fa-facebook-square", "fa-fast-backward", "fa-fast-forward", "fa-female", "fa-fighter-jet", "fa-file", "fa-file-o", "fa-file-text", "fa-file-text-o", "fa-files-o", "fa-film", "fa-filter", "fa-fire", "fa-fire-extinguisher", "fa-flag", "fa-flag-checkered", "fa-flag-o", "fa-flash", "fa-flask", "fa-flickr", "fa-floppy-o", "fa-folder", "fa-folder-o", "fa-folder-open", "fa-folder-open-o", "fa-font", "fa-forward", "fa-foursquare", "fa-frown-o", "fa-gamepad", "fa-gavel", "fa-gbp", "fa-gear", "fa-gears", "fa-gift", "fa-github", "fa-github-alt", "fa-github-square", "fa-gittip", "fa-glass", "fa-globe", "fa-google-plus", "fa-google-plus-square", "fa-group", "fa-h-square", "fa-hand-o-down", "fa-hand-o-left", "fa-hand-o-right", "fa-hand-o-up", "fa-hdd-o", "fa-headphones", "fa-heart", "fa-heart-o", "fa-home", "fa-hospital-o", "fa-html5", "fa-inbox", "fa-indent", "fa-info", "fa-info-circle", "fa-inr", "fa-instagram", "fa-italic", "fa-jpy", "fa-key", "fa-keyboard-o", "fa-krw", "fa-laptop", "fa-leaf", "fa-legal", "fa-lemon-o", "fa-level-down", "fa-level-up", "fa-lightbulb-o", "fa-link", "fa-linkedin", "fa-linkedin-square", "fa-linux", "fa-list", "fa-list-alt", "fa-list-ol", "fa-list-ul", "fa-location-arrow", "fa-lock", "fa-long-arrow-down", "fa-long-arrow-left", "fa-long-arrow-right", "fa-long-arrow-up", "fa-magic", "fa-magnet", "fa-mail-forward", "fa-mail-reply", "fa-mail-reply-all", "fa-male", "fa-map-marker", "fa-maxcdn", "fa-medkit", "fa-meh-o", "fa-microphone", "fa-microphone-slash", "fa-minus", "fa-minus-circle", "fa-minus-square", "fa-minus-square-o", "fa-mobile", "fa-mobile-phone", "fa-money", "fa-moon-o", "fa-music", "fa-outdent", "fa-pagelines", "fa-paperclip", "fa-paste", "fa-pause", "fa-pencil", "fa-pencil-square", "fa-pencil-square-o", "fa-phone", "fa-phone-square", "fa-picture-o", "fa-pinterest", "fa-pinterest-square", "fa-plane", "fa-play", "fa-play-circle", "fa-play-circle-o", "fa-plus", "fa-plus-circle", "fa-plus-square", "fa-plus-square-o", "fa-power-off", "fa-print", "fa-puzzle-piece", "fa-qrcode", "fa-question", "fa-question-circle", "fa-quote-left", "fa-quote-right", "fa-random", "fa-refresh", "fa-renren", "fa-repeat", "fa-reply", "fa-reply-all", "fa-retweet", "fa-rmb", "fa-road", "fa-rocket", "fa-rotate-left", "fa-rotate-right", "fa-rouble", "fa-rss", "fa-rss-square", "fa-rub", "fa-ruble", "fa-rupee", "fa-save", "fa-scissors", "fa-search", "fa-search-minus", "fa-search-plus", "fa-share", "fa-share-square", "fa-share-square-o", "fa-shield", "fa-shopping-cart", "fa-sign-in", "fa-sign-out", "fa-signal", "fa-sitemap", "fa-skype", "fa-smile-o", "fa-sort", "fa-sort-alpha-asc", "fa-sort-alpha-desc", "fa-sort-amount-asc", "fa-sort-amount-desc", "fa-sort-asc", "fa-sort-desc", "fa-sort-down", "fa-sort-numeric-asc", "fa-sort-numeric-desc", "fa-sort-up", "fa-spinner", "fa-square", "fa-square-o", "fa-stack-exchange", "fa-stack-overflow", "fa-star", "fa-star-half", "fa-star-half-empty", "fa-star-half-full", "fa-star-half-o", "fa-star-o", "fa-step-backward", "fa-step-forward", "fa-stethoscope", "fa-stop", "fa-strikethrough", "fa-subscript", "fa-suitcase", "fa-sun-o", "fa-superscript", "fa-table", "fa-tablet", "fa-tachometer", "fa-tag", "fa-tags", "fa-tasks", "fa-terminal", "fa-text-height", "fa-text-width", "fa-th", "fa-th-large", "fa-th-list", "fa-thumb-tack", "fa-thumbs-down", "fa-thumbs-o-down", "fa-thumbs-o-up", "fa-thumbs-up", "fa-ticket", "fa-times", "fa-times-circle", "fa-times-circle-o", "fa-tint", "fa-toggle-down", "fa-toggle-left", "fa-toggle-right", "fa-toggle-up", "fa-trash-o", "fa-trello", "fa-trophy", "fa-truck", "fa-try", "fa-tumblr", "fa-tumblr-square", "fa-turkish-lira", "fa-twitter", "fa-twitter-square", "fa-umbrella", "fa-underline", "fa-undo", "fa-unlink", "fa-unlock", "fa-unlock-alt", "fa-unsorted", "fa-upload", "fa-usd", "fa-user", "fa-user-md", "fa-users", "fa-video-camera", "fa-vimeo-square", "fa-vk", "fa-volume-down", "fa-volume-off", "fa-volume-up", "fa-warning", "fa-weibo", "fa-wheelchair", "fa-windows", "fa-won", "fa-wrench", "fa-xing", "fa-xing-square", "fa-yen", "fa-youtube", "fa-youtube-play" };

            var arrList = Enumerable.Repeat(new { Key = "", Value = "" }, 0).ToList();

            foreach (var item in arr)
            {
                arrList.Add(new { Key = "fa " + item, Value = item.Remove(0, 3) });
            }
            var list = new SelectList(arrList.ToArray(), "Key", "Value", selectedIcon);

            return(SelectExtensions.DropDownList(html, name, list, "Select icon", htmlAttributes));
        }
Ejemplo n.º 11
0
        public static MvcHtmlString JQM_SelectMenu(this HtmlHelper htmlHelper, string name, string label, MultiSelectList values, string optionLabel = null, SelectMenuConfig config = null)
        {
            TagBuilder tagResult = new TagBuilder("div");

            tagResult.MergeAttribute("class", "ui-field-contain");
            if (config == null)
            {
                config = new SelectMenuConfig();
            }

            tagResult.InnerHtml += LabelExtensions.Label(htmlHelper, "", label).ToHtmlString();
            tagResult.InnerHtml += SelectExtensions.DropDownList(htmlHelper, name, values, optionLabel, (config != null) ? config.GetAttributes() : null).ToHtmlString();
            return(tagResult.ToHtml());
        }
Ejemplo n.º 12
0
        public static MvcHtmlString DropDownList <TModel, TEnum>(
            this HtmlHelper <TModel> htmlHelper,
            string name,
            TEnum?selectedValue) where TEnum : struct
        {
            IEnumerable <TEnum> values = Enum.GetValues(typeof(TEnum))
                                         .Cast <TEnum>();
            IEnumerable <SelectListItem> items = from value in values
                                                 select new SelectListItem()
            {
                Text     = value.ToString(),
                Value    = EnumUtil.GetCode <TEnum>(value),
                Selected = (value.Equals(selectedValue))
            };

            return(SelectExtensions.DropDownList(htmlHelper, name, items));
        }
Ejemplo n.º 13
0
        public static MvcHtmlString YesOrNo(this HtmlHelper htmlHelper, string name, string optionLabel, object htmlAttributes, string defaultText)
        {
            IList <SelectListItem> selectList = new List <SelectListItem>();

            if (defaultText != "")
            {
                selectList.Add(new SelectListItem {
                    Selected = true, Text = defaultText, Value = "-1"
                });
            }
            selectList.Add(new SelectListItem {
                Text = "No", Value = "0"
            });
            selectList.Add(new SelectListItem {
                Text = "Yes", Value = "1"
            });
            return(SelectExtensions.DropDownList(htmlHelper, name, selectList, optionLabel, htmlAttributes));
        }
Ejemplo n.º 14
0
        public static MvcHtmlString EnumDropdownFor <TModel, TValue>(this HtmlHelper <TModel> html, Expression <Func <TModel, TValue> > expression)
        {
            var memberName   = (expression.Body as MemberExpression).Member.Name;
            var propertyInfo = typeof(TModel).GetProperty(memberName);

            Type enumType = null;

            if (propertyInfo.PropertyType.IsEnum)
            {
                enumType = propertyInfo.PropertyType;
            }
            else
            {
                var attributes = propertyInfo.GetCustomAttributes(typeof(EnumDataTypeAttribute), true);
                if (attributes == null || attributes.Length == 0)
                {
                    throw new Exception("cannot resolve enum type");
                }

                enumType = (attributes[0] as EnumDataTypeAttribute).EnumType;
                if (enumType == null)
                {
                    throw new Exception("cannot resolve enum type");
                }
            }

            var enumValues = Enum.GetValues(enumType);
            List <SelectListItem> items = new List <SelectListItem>();

            foreach (var value in enumValues)
            {
                items.Add(new SelectListItem()
                {
                    Value = ((int)value).ToString(), Text = EnumHelper.GetText(value)
                });
            }

            return(SelectExtensions.DropDownList(html, memberName, items, ""));
        }
Ejemplo n.º 15
0
        public static MvcHtmlString GenderDropDown(this HtmlHelper helper, string name, string nameval, SelectList values, Object htmlAttributes)
        {
            //Razor html example (Create):
            //@Html.GenderDropDown("gGender", "", new SelectList(new[] { "" }), new { @class = "form-control" })
            //Razor html example (Edit):
            //@Html.GenderDropDown("gGender", Model.gGender, new SelectList(new[] { "" }), new { @class = "form-control" })

            List <SelectListItem> selItems = new List <SelectListItem>();

            if (nameval.ToLower() == "f")
            {
                selItems.Add(new SelectListItem()
                {
                    Text = "Female", Value = "F", Selected = true
                });
                selItems.Add(new SelectListItem()
                {
                    Text = "Male", Value = "M", Selected = false
                });
            }
            else
            {
                selItems.Add(new SelectListItem()
                {
                    Text = "Female", Value = "F", Selected = false
                });
                selItems.Add(new SelectListItem()
                {
                    Text = "Male", Value = "M", Selected = true
                });
            }

            return(SelectExtensions.DropDownList(helper,
                                                 name,
                                                 selItems,
                                                 htmlAttributes));
        }
Ejemplo n.º 16
0
 public MvcHtmlString DropDownList(string name, SelectList selectList)
 {
     return(SelectExtensions.DropDownList(this, name, selectList));
 }
Ejemplo n.º 17
0
        public static MvcHtmlString WizardStepBody(this HtmlHelper html, WizardManager wm, object stepModel)
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append("\r\n");
            PropertyInfo[] properties = stepModel.GetType().GetProperties();
            for (int i = 0; i < properties.Length; i++)
            {
                PropertyInfo propertyInfo = properties[i];
                object       obj_         = propertyInfo.GetGetMethod().Invoke(stepModel, null);
                if (obj_ == null)
                {
                    obj_ = "";
                }
                TagBuilder tagBuilder = new TagBuilder("div");
                tagBuilder.MergeAttribute("class", "wizardfield");
                if (propertyInfo.PropertyType == typeof(bool))
                {
                    tagBuilder.InnerHtml = propertyInfo.Name + ":  " + InputExtensions.CheckBox(html, propertyInfo.Name, obj_).ToHtmlString();
                }
                else
                {
                    if (propertyInfo.PropertyType.IsSubclassOf(typeof(Enum)))
                    {
                        List <SelectListItem> list       = new List <SelectListItem>();
                        IEnumerator           enumerator = Enum.GetValues(propertyInfo.PropertyType).GetEnumerator();
                        try
                        {
                            while (enumerator.MoveNext())
                            {
                                Enum @enum = (Enum)enumerator.Current;
                                List <SelectListItem> varJWA0        = list;
                                SelectListItem        selectListItem = new SelectListItem();
                                selectListItem.Selected = false;
                                selectListItem.Text     = @enum.ToString();
                                selectListItem.Value    = @enum.ToString();
                                varJWA0.Add(selectListItem);
                            }
                        }
                        finally
                        {
                            IDisposable disposable_ = enumerator as IDisposable;
                            if (disposable_ != null)
                            {
                                disposable_.Dispose();
                            }
                        }
                        tagBuilder.InnerHtml = propertyInfo.Name + ":  " + SelectExtensions.DropDownList(html, propertyInfo.Name, list).ToHtmlString();
                    }
                    else
                    {
                        tagBuilder.InnerHtml = propertyInfo.Name + ":  " + InputExtensions.TextBox(html, propertyInfo.Name, obj_).ToHtmlString();
                    }
                }
                stringBuilder.Append(tagBuilder.ToString()).Append("\r\n");
            }
            TagBuilder tagBuilder2 = new TagBuilder("div");

            tagBuilder2.MergeAttribute("class", "wizardbody");
            tagBuilder2.InnerHtml = stringBuilder.ToString();
            return(MvcHtmlString.Create(tagBuilder2.ToString()));
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Creates the DropDownList component with the remote content.
        /// </summary>
        /// <typeparam name="T">The model</typeparam>
        /// <typeparam name="U">The property</typeparam>
        /// <param name="htmlHelper">The HtmlHelper</param>
        /// <param name="expression">The expression for the propperty</param>
        /// <param name="action">The action name to get the content</param>
        /// <returns>Returns the DropDownList component with the remote content</returns>
        public static MvcHtmlString RemoteDropDownListFor <T, U>(this HtmlHelper <T> htmlHelper, Expression <Func <T, U> > expression, string action)
        {
            ModelMetadata metadata = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData);

            return(SelectExtensions.DropDownList(htmlHelper, metadata.PropertyName, new List <SelectListItem>(), new { @class = "referencelist form-control", data_action = action, data_selected = metadata.Model }));
        }