本文整理汇总了C#中HtmlHelper.ListBox方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlHelper.ListBox方法的具体用法?C# HtmlHelper.ListBox怎么用?C# HtmlHelper.ListBox使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HtmlHelper
的用法示例。
在下文中一共展示了HtmlHelper.ListBox方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetPreferenceControl
/// <summary>Generate a control for a set preference.</summary>
private static string SetPreferenceControl(HtmlHelper helper, MetaAttribute ma, Preference preference)
{
string result;
if (ma.HasChoices)
{
if (preference != null)
{
MultiSelectList listData = new MultiSelectList(SelectHelper.DropDownRecordsFromValueSet(ma.ChoicesCollection), "Value", "Text",
SelectHelper.ValuesFromValueSet(preference.Set));
result = helper.ListBox(ma.PreferenceSetControlName, listData);
}
else
{
MultiSelectList listData = new MultiSelectList(SelectHelper.DropDownRecordsFromValueSet(ma.ChoicesCollection), "Value", "Text");
result = helper.ListBox(ma.PreferenceSetControlName, listData);
}
}
else
{
if (preference != null)
{
result = helper.TextBox(ma.PreferenceSetControlName, preference.RawValues);
}
else
{
result = helper.TextBox(ma.PreferenceSetControlName);
}
}
return result;
}
示例2: WriteInput
public override MvcHtmlString WriteInput(HtmlHelper helper, object htmlAttributes)
{
IDictionary<string, object> efHtmlAttributes = new RouteValueDictionary(htmlAttributes);
AddCommonHtmlAttributes(efHtmlAttributes);
// This is an ugly hack. For some reason, when inputName is used here, the Select attributes don't render and the selection is lost.
// See here for possible explanation: http://stackoverflow.com/questions/3737985/asp-net-mvc-multiselectlist-with-selected-values-not-selecting-properly
return helper.ListBox(this.InputName + "01", this.SelectListItems, efHtmlAttributes);
}
示例3: 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();
}
示例4: ListBoxForParameter
private static MvcHtmlString ListBoxForParameter(HtmlHelper htmlHelper, ReportParameter reportParameter, bool disabled)
{
Dictionary<string, object> htmlAttributes = GetHtmlAttributes(reportParameter.Dependents, null, disabled);
return htmlHelper.ListBox(reportParameter.Id, reportParameter.Options, htmlAttributes);
}