本文整理汇总了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);
}
示例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);
}
示例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);
}
示例4: BooleanTemplateDropDownList
private static string BooleanTemplateDropDownList(HtmlHelper html, bool? value)
{
return html.DropDownList(String.Empty, TriStateValues(value), CreateHtmlAttributes(html, "list-box tri-state")).ToHtmlString();
}
示例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 });
}
示例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;
}
示例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();
}
示例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();
}
示例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();
}
示例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);
}
示例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);
}