当前位置: 首页>>代码示例>>C#>>正文


C# HtmlHelper.DropDownList方法代码示例

本文整理汇总了C#中HtmlHelper.DropDownList方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlHelper.DropDownList方法的具体用法?C# HtmlHelper.DropDownList怎么用?C# HtmlHelper.DropDownList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HtmlHelper的用法示例。


在下文中一共展示了HtmlHelper.DropDownList方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RangePreferenceControl

        /// <summary>Generate a control for a range preference.</summary>
        private static string RangePreferenceControl(HtmlHelper helper, MetaAttribute ma, Preference preference)
        {
            string lowerBoundControl;
            string upperBoundControl;
            string currentLowerBound = null;
            string currentUpperBound = null;

            if (preference != null)
            {
                currentLowerBound = (preference.Range.LowerBound != null) ? preference.Range.LowerBound.Formatted : String.Empty;
                currentUpperBound = (preference.Range.UpperBound != null) ? preference.Range.UpperBound.Formatted : String.Empty;
            }

            if (ma.HasChoices)
            {
                SelectList lowerBoundListData = (preference != null)
                    ? new SelectList(SelectHelper.DropDownRecordsFromValueSet(ma.ChoicesCollection), "Value", "Text", currentLowerBound)
                    : new SelectList(SelectHelper.DropDownRecordsFromValueSet(ma.ChoicesCollection), "Value", "Text");
                SelectList upperBoundListData = (preference != null)
                    ? new SelectList(SelectHelper.DropDownRecordsFromValueSet(ma.ChoicesCollection), "Value", "Text", currentUpperBound)
                    : new SelectList(SelectHelper.DropDownRecordsFromValueSet(ma.ChoicesCollection), "Value", "Text");

                lowerBoundControl = helper.DropDownList(ma.PreferenceLowerBoundHtmlControlName, lowerBoundListData, OPTION_LABEL);
                upperBoundControl = helper.DropDownList(ma.PreferenceUpperBoundHtmlControlName, upperBoundListData, OPTION_LABEL);
            }
            else
            {
                lowerBoundControl = helper.TextBox(ma.PreferenceLowerBoundHtmlControlName, currentLowerBound, new {length=10});
                upperBoundControl = helper.TextBox(ma.PreferenceUpperBoundHtmlControlName, currentUpperBound, new {length=10});
            }

            return String.Format(
                "From {2}{0} to {2}{1}", lowerBoundControl, upperBoundControl, (ma.DataTypeEnum == MetaAttribute.MetaAttributeDataType.CURRENCY) ? "$" : String.Empty);
        }
开发者ID:liammclennan,项目名称:Herald,代码行数:35,代码来源:BuyerHelper.cs

示例2: SelectableAttribute

        private static string SelectableAttribute(HtmlHelper helper, MetaAttribute ma, ProductAttribute attribute)
        {
            SelectList listData = (attribute != null)
                        ? new SelectList(SelectHelper.DropDownRecordsFromValueSet(ma.ChoicesCollection), "Value", "Text", (object)attribute.RawValue)
                        : new SelectList(SelectHelper.DropDownRecordsFromValueSet(ma.ChoicesCollection), "Value", "Text");

            return helper.DropDownList(ma.ProductAttributeHtmlControlName, listData, OPTION_LABEL);
        }
开发者ID:liammclennan,项目名称:Herald,代码行数:8,代码来源:ProductHelper.cs

示例3: WriteInput

        public override MvcHtmlString WriteInput(HtmlHelper helper, object htmlAttributes)
        {
            IDictionary<string, object> efHtmlAttributes = new RouteValueDictionary(htmlAttributes);
            AddCommonHtmlAttributes(efHtmlAttributes);

            // Make sure that the select list item matching the Value property is selected before rending the list.
            IEnumerable<SelectListItem> selectListItems = this.SelectListItems.Select(x =>
                new SelectListItem()
                {
                    Text = x.Text,
                    Value = x.Value,
                    Selected = x.Value == Value
                });

            return helper.DropDownList(this.InputName, selectListItems, efHtmlAttributes);
        }
开发者ID:rupeshtelang,项目名称:ExpressForms,代码行数:16,代码来源:ExpressFormsDropDownList.cs

示例4: BooleanTemplateDropDownList

 private static string BooleanTemplateDropDownList(HtmlHelper html, bool? value)
 {
     return html.DropDownList(String.Empty, TriStateValues(value), CreateHtmlAttributes(html, "list-box tri-state")).ToHtmlString();
 }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:4,代码来源:DefaultEditorTemplates.cs

示例5: ThemeVarSelectEditor

        private static MvcHtmlString ThemeVarSelectEditor(HtmlHelper html, ThemeVariableInfo info, string expression, string value)
        {
            var manifest = info.Manifest; 

            if (!manifest.Selects.ContainsKey(info.SelectRef))
            {
                throw new SmartException("A select list with id '{0}' was not specified. Please specify a 'Select' element with at least one 'Option' child.", info.SelectRef);
            }

			//var isDefault = value.IsCaseInsensitiveEqual(info.DefaultValue);

            var selectList = from x in manifest.Selects[info.SelectRef]
                             select new SelectListItem 
                             { 
                                 Value = x, 
                                 Text = x, // TODO: (MC) Localize
                                 Selected = x.IsCaseInsensitiveEqual(value) 
                             };

			return html.DropDownList(expression, selectList, new { placeholder = info.DefaultValue });
        }
开发者ID:boatengfrankenstein,项目名称:SmartStoreNET,代码行数:21,代码来源:ThemeHtmlExtensions.cs

示例6: StandardEnumValueList

        /// <summary>
        /// 生成普通枚举类型的枚举值列表
        /// </summary>
        /// <param name="htmlHelper"></param>
        /// <param name="name"></param>
        /// <param name="enumType"></param>
        /// <param name="filter"></param>
        /// <param name="enumValue"></param>
        /// <param name="optionLabel"></param>
        /// <param name="includeZero"></param>
        /// <param name="htmlAttributes"></param>
        /// <returns></returns>
        private static MvcHtmlString StandardEnumValueList(HtmlHelper htmlHelper, string name,
            Type enumType, IEnumFilter filter, int enumValue, string optionLabel, bool includeZero, object htmlAttributes)
        {
            IList<SelectListItem> items = new List<SelectListItem>();
            foreach (FieldInfo fieldInfo in enumType.GetFields(BindingFlags.Public | BindingFlags.Static))
            {
                // 筛选
                if (filter != null)
                {
                    if (!filter.Test(fieldInfo))
                    {
                        continue;
                    }
                }

                object value = fieldInfo.GetValue(null);
                int intValue = Convert.ToInt32(value);

                if (!includeZero && intValue == 0)
                {
                    continue;
                }

                object[] attributes = fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), true);
                if (attributes.Length == 0)
                {
                    items.Add(new SelectListItem()
                    {
                        Value = intValue.ToString(),
                        Text = value.ToString(),
                        Selected = (enumValue == intValue),
                    });
                }
                else
                {
                    DescriptionAttribute description = attributes[0] as DescriptionAttribute;
                    items.Add(new SelectListItem()
                    {
                        Value = intValue.ToString(),
                        Text = description.Description,
                        Selected = (enumValue == intValue),
                    });
                }
            }

            object currentValue = htmlHelper.ViewData.Eval(name);
            htmlHelper.ViewData[name] = enumValue;
            MvcHtmlString result = htmlHelper.DropDownList(name, items, optionLabel, htmlAttributes);
            htmlHelper.ViewData[name] = currentValue;
            return result;
        }
开发者ID:shenlos,项目名称:dukous-boss,代码行数:63,代码来源:EnumValueExtensions.cs

示例7: Render

 /// <summary>
 /// Renders the specified HTML.
 /// </summary>
 /// <param name="html">The HTML helper.</param>
 /// <param name="name">The element name.</param>
 /// <param name="value">The element value.</param>
 /// <param name="values">The element values.</param>
 /// <returns>Returns element html code.</returns>
 public override String Render(HtmlHelper html, String name, String value, String values)
 {
     return html.DropDownList(name, ParseValues(values, value)).ToString();
 }
开发者ID:coreframework,项目名称:Core-Framework,代码行数:12,代码来源:SelectBoxAttribute.cs

示例8: RenderSelectElement

        public static string RenderSelectElement(HtmlHelper html, BootstrapSelectElementModel model, BootstrapInputType inputType)
        {
            if (model == null || string.IsNullOrEmpty(model.htmlFieldName) || model.selectList == null) return null;

            string combinedHtml = "{0}{1}{2}";
            if (model.selectedValue != null)
            {
                foreach (var item in model.selectList)
                {
                    if (item.Value == model.selectedValue.ToString())
                        item.Selected = true;
                }
            }

            model.htmlAttributes.AddRange(html.GetUnobtrusiveValidationAttributes(model.htmlFieldName, model.metadata));
            if (model.tooltipConfiguration != null) model.htmlAttributes.AddRange(model.tooltipConfiguration.ToDictionary());
            if (!string.IsNullOrEmpty(model.id)) model.htmlAttributes.AddOrReplace("id", model.id);

            // assign size class
            model.htmlAttributes.AddOrMergeCssClass("class", BootstrapHelper.GetClassForInputSize(model.size));

            // build html for input
            string input = string.Empty;

            if(inputType == BootstrapInputType.DropDownList)
                input = html.DropDownList(model.htmlFieldName, model.selectList, model.optionLabel, model.htmlAttributes.FormatHtmlAttributes()).ToHtmlString();

            if(inputType == BootstrapInputType.ListBox)
                input = html.ListBox(model.htmlFieldName, model.selectList, model.htmlAttributes.FormatHtmlAttributes()).ToHtmlString();

            // account for appendString, prependString, and AppendButtons
            TagBuilder appendPrependContainer = new TagBuilder("div");
            if (!string.IsNullOrEmpty(model.prependString) | !string.IsNullOrEmpty(model.appendString) | model.appendButtons.Count() > 0)
            {
                string addOnPrependString = "";
                string addOnAppendString = "";
                string addOnPrependButtons = "";
                string addOnAppendButtons = "";

                TagBuilder addOn = new TagBuilder("span");
                addOn.AddCssClass("add-on");
                if (!string.IsNullOrEmpty(model.prependString))
                {
                    appendPrependContainer.AddOrMergeCssClass("input-prepend");
                    addOn.InnerHtml = model.prependString;
                    addOnPrependString = addOn.ToString();
                }
                if (!string.IsNullOrEmpty(model.appendString))
                {
                    appendPrependContainer.AddOrMergeCssClass("input-append");
                    addOn.InnerHtml = model.appendString;
                    addOnAppendString = addOn.ToString();
                }
                if (model.appendButtons.Count() > 0)
                {
                    appendPrependContainer.AddOrMergeCssClass("input-append");
                    ((List<BootstrapButton>)model.appendButtons).ForEach(x => addOnAppendButtons += x.ToHtmlString());
                }
                if (model.prependButtons.Count() > 0)
                {
                    appendPrependContainer.AddOrMergeCssClass("input-append");
                    ((List<BootstrapButton>)model.prependButtons).ForEach(x => addOnPrependButtons += x.ToHtmlString());
                }

                appendPrependContainer.InnerHtml = addOnPrependButtons + addOnPrependString + "{0}" + addOnAppendString + addOnAppendButtons;
                combinedHtml = appendPrependContainer.ToString(TagRenderMode.Normal) + "{1}{2}";
            }

            string helpText = model.helpText != null ? model.helpText.ToHtmlString() : string.Empty;
            string validationMessage = "";
            if (model.displayValidationMessage)
            {
                string validation = html.ValidationMessage((string)model.htmlFieldName).ToHtmlString();
                validationMessage = new BootstrapHelpText(validation, model.validationMessageStyle).ToHtmlString();
            }

            return MvcHtmlString.Create(string.Format(combinedHtml, input, validationMessage, helpText)).ToString();
        }
开发者ID:bbqchickenrobot,项目名称:TwitterBootstrapMvc,代码行数:78,代码来源:Renderer.SelectElement.cs

示例9: RenderElementByType

        private static String RenderElementByType(HtmlHelper html, FormElement model, String elementName, String elementValue)
        {
            var builder = new StringBuilder();
            switch (model.Type)
            {
                case FormElementType.TextField:
                    {
                        builder.Append(html.Encode(model.Title));
                        break;
                    }
                case FormElementType.TextBox:
                    {
                        builder.Append(html.Label(elementName, model.Title));
                        builder.Append("<br/>");
                        builder.Append(html.TextBox(elementName, elementValue));
                        break;
                    }
                case FormElementType.TextArea:
                    {
                        builder.Append(html.Label(elementName, model.Title));
                        builder.Append("<br/>");
                        builder.Append(html.TextArea(elementName, elementValue));
                        break;
                    }
                case FormElementType.CheckBox:
                    {
                        builder.Append(html.SimpleCheckBox(elementName, FormCollectionExtensions.BooleanValue(elementValue)));
                        builder.Append(html.Label(elementName, model.Title));
                        break;
                    }
                case FormElementType.DropDownList:
                    {
                        builder.Append(html.Label(elementName, model.Title));
                        builder.Append("<br/>");
                        builder.Append(html.DropDownList(elementName, ParseElementValuesForDropDown(model.ElementValues, elementValue)));
                        break;
                    }
                case FormElementType.RadioButtons:
                    {
                        builder.Append(html.Label(elementName, model.Title));
                        builder.Append("<br/>");
                        builder.Append(html.RadioList(elementName, ParseElementValuesForRadioButtons(model.ElementValues, elementName), elementValue));
                        break;
                    }
                case FormElementType.Captcha:
                    {
                        builder.Append(html.CaptchaImage(CaptchaDefaultHeight, CaptchaDefaultWidth));
                        builder.Append(html.Label(elementName, String.Empty));
                        builder.Append("<br/>");
                        builder.Append(html.CaptchaTextBox(elementName));
                        break;
                    }

                default:
                    break;
            }

            return builder.ToString();
        }
开发者ID:coreframework,项目名称:Core-Framework,代码行数:59,代码来源:FormElementsExtensions.cs

示例10: DateRangeDropDownForParameter

        private static MvcHtmlString DateRangeDropDownForParameter(HtmlHelper htmlHelper, ReportParameter reportParameter, bool disabled)
        {
            Dictionary<string, object> htmlAttributes = GetHtmlAttributes(reportParameter.Dependents, null, disabled, "enableDependents");
            htmlAttributes.Add("data-value", ReportParameter.CustomDateRangeValue);

            return htmlHelper.DropDownList(reportParameter.Id, reportParameter.Options, htmlAttributes);
        }
开发者ID:shayaneumar,项目名称:gabbar,代码行数:7,代码来源:ReportingExtensions.cs

示例11: DropDownForParameter

 private static MvcHtmlString DropDownForParameter(HtmlHelper htmlHelper, ReportParameter reportParameter, bool disabled)
 {
     Dictionary<string, object> htmlAttributes = GetHtmlAttributes(reportParameter.Dependents, null, disabled);
     
     return htmlHelper.DropDownList(reportParameter.Id, reportParameter.Options, htmlAttributes);
 }
开发者ID:shayaneumar,项目名称:gabbar,代码行数:6,代码来源:ReportingExtensions.cs


注:本文中的HtmlHelper.DropDownList方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。