本文整理汇总了C#中System.Web.Mvc.HtmlHelper.TextBox方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlHelper.TextBox方法的具体用法?C# HtmlHelper.TextBox怎么用?C# HtmlHelper.TextBox使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Mvc.HtmlHelper
的用法示例。
在下文中一共展示了HtmlHelper.TextBox方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RenderFile
public static string RenderFile(HtmlHelper html, BootstrapFileModel model)
{
string validationMessage = "";
if(model.displayValidationMessage && html.ValidationMessage(model.htmlFieldName) != null )
{
string validation = html.ValidationMessage(model.htmlFieldName).ToHtmlString();
validationMessage = new BootstrapHelpText(validation, model.validationMessageStyle).ToHtmlString();
}
model.htmlAttributes.MergeHtmlAttributes(html.GetUnobtrusiveValidationAttributes(model.htmlFieldName, model.metadata));
if (model.tooltipConfiguration != null) model.htmlAttributes.MergeHtmlAttributes(model.tooltipConfiguration.ToDictionary());
if (model.tooltip != null) model.htmlAttributes.MergeHtmlAttributes(model.tooltip.ToDictionary());
var mergedHtmlAttrs = model.htmlAttributes.FormatHtmlAttributes().AddOrReplace("type", "File");
if (!string.IsNullOrEmpty(model.id)) mergedHtmlAttrs.AddOrReplace("id", model.id);
return html.TextBox(model.htmlFieldName, null, mergedHtmlAttrs).ToHtmlString() + validationMessage;
}
示例2: RenderDatePicker
//.........这里部分代码省略.........
if(model.multidate)
model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.multidate), model.multidate.ToString().ToLower());
if(!string.IsNullOrEmpty(model.multidateSeparator))
model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.multidateSeparator), model.multidateSeparator);
if(!string.IsNullOrEmpty(model.orientation))
model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.orientation), model.orientation);
if(!model.showOnFocus)
model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.showOnFocus), model.showOnFocus.ToString().ToLower());
if(model.startDate != null)
model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.startDate), model.startDate.ToString());
if(model.startView != 0)
model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.startView), model.startView.ToString());
if(!string.IsNullOrEmpty(model.title))
model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.title), model.title);
if(!string.IsNullOrEmpty(model.todayBtn))
model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.todayBtn), model.todayBtn);
if (model.todayHighlight)
model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.todayHighlight), model.todayHighlight.ToString().ToLower());
if(model.toggleActive)
model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.toggleActive), model.toggleActive.ToString().ToLower());
if(model.zIndexOffset != 10)
model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.zIndexOffset), model.zIndexOffset.ToString());
htmlAttributes.MergeHtmlAttributes(model.htmlAttributes.FormatHtmlAttributes());
var input = html.TextBox(model.htmlFieldName, model.value, model.format, htmlAttributes).ToHtmlString();
container.AddOrMergeCssClass("input-group");
//container.AddOrMergeCssClass("date-picker");
addOn.AddCssClass("input-group-addon");
addOn.InnerHtml = new Icon(Icons.Calendar, Size.Lg).ToHtmlString();
addOnAppendIcon = addOn.ToString();
if (!string.IsNullOrEmpty(model.prependString) || model.iconPrepend != Icons._not_set || !string.IsNullOrEmpty(model.iconPrependCustomClass))
{
if (!string.IsNullOrEmpty(model.prependString))
{
addOn.InnerHtml = model.prependString;
addOnPrependString = addOn.ToString();
}
if (model.iconPrepend != Icons._not_set)
{
addOn.InnerHtml = new Icon(model.iconPrepend, model.iconPrependIsWhite).ToHtmlString();
addOnPrependIcon = addOn.ToString();
}
if (!string.IsNullOrEmpty(model.iconPrependCustomClass))
{
var i = new TagBuilder("i");
i.AddCssClass(model.iconPrependCustomClass);
addOn.InnerHtml = i.ToString(TagRenderMode.Normal);
addOnPrependIcon = addOn.ToString();
}
}
container.InnerHtml = addOnPrependIcon + addOnPrependString + "{0}" + addOnAppendIcon;
combinedHtml = container.ToString(TagRenderMode.Normal) + "{1}{2}";
var helpText = model.helpText != null ? model.helpText.ToHtmlString() : string.Empty;
var validationMessage = "";
if (model.displayValidationMessage)
{
var validation = html.ValidationMessage(model.htmlFieldName).ToHtmlString();
validationMessage = new HelpText(validation, model.validationMessageStyle).ToHtmlString();
}
string htmlTextBox = string.Format(combinedHtml, input, helpText, validationMessage);
TagBuilder inputWrapper = null;
if (!string.IsNullOrEmpty(model.inputElementWrapper))
{
inputWrapper = new TagBuilder(model.inputElementWrapper);
if (model.inputElementWrapperAttributes != null)
inputWrapper.MergeAttributes(HtmlHelper.AnonymousObjectToHtmlAttributes(model.inputElementWrapperAttributes));
inputWrapper.InnerHtml = htmlTextBox;
}
string htmlString = inputWrapper != null
? inputWrapper.ToString(TagRenderMode.Normal)
: htmlTextBox;
return new HtmlString(htmlString);
}
示例3: RenderTextBox
public static string RenderTextBox(HtmlHelper html, BootstrapTextBoxModel model, bool isPassword)
{
var combinedHtml = "{0}{1}{2}";
model.htmlAttributes.MergeHtmlAttributes(html.GetUnobtrusiveValidationAttributes(model.htmlFieldName, model.metadata));
if (!string.IsNullOrEmpty(model.id)) model.htmlAttributes.Add("id", model.id);
if (model.tooltipConfiguration != null) model.htmlAttributes.MergeHtmlAttributes(model.tooltipConfiguration.ToDictionary());
if (model.tooltip != null) model.htmlAttributes.MergeHtmlAttributes(model.tooltip.ToDictionary());
if (model.typehead != null) model.htmlAttributes.MergeHtmlAttributes(model.typehead.ToDictionary(html));
// assign placeholder class
if (!string.IsNullOrEmpty(model.placeholder)) model.htmlAttributes.Add("placeholder", model.placeholder);
// assign size class
model.htmlAttributes.AddOrMergeCssClass("class", BootstrapHelper.GetClassForInputSize(model.size));
// build html for input
var input = isPassword
? html.Password(model.htmlFieldName, null, model.htmlAttributes.FormatHtmlAttributes()).ToHtmlString()
: html.TextBox(model.htmlFieldName, model.value, model.format, model.htmlAttributes.FormatHtmlAttributes()).ToHtmlString();
// account for appendString, prependString, and AppendButtons
if (!string.IsNullOrEmpty(model.prependString) ||
!string.IsNullOrEmpty(model.appendString) ||
model.prependButtons.Any() ||
model.appendButtons.Any() ||
model.iconPrepend != Icons._not_set ||
model.iconAppend != Icons._not_set ||
!string.IsNullOrEmpty(model.iconPrependCustomClass) ||
!string.IsNullOrEmpty(model.iconAppendCustomClass))
{
var appendPrependContainer = new TagBuilder("div");
var addOnPrependString = "";
var addOnAppendString = "";
var addOnPrependButtons = "";
var addOnAppendButtons = "";
var addOnPrependIcon = "";
var addOnAppendIcon = "";
var 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.prependButtons.Count > 0)
{
appendPrependContainer.AddOrMergeCssClass("input-prepend");
model.prependButtons.ForEach(x => addOnPrependButtons += x.ToHtmlString());
}
if (model.appendButtons.Count > 0)
{
appendPrependContainer.AddOrMergeCssClass("input-append");
model.appendButtons.ForEach(x => addOnAppendButtons += x.ToHtmlString());
}
if (model.iconPrepend != Icons._not_set)
{
appendPrependContainer.AddOrMergeCssClass("input-prepend");
addOn.InnerHtml = new BootstrapIcon(model.iconPrepend, model.iconPrependIsWhite).ToHtmlString();
addOnPrependIcon = addOn.ToString();
}
if (model.iconAppend != Icons._not_set)
{
appendPrependContainer.AddOrMergeCssClass("input-append");
addOn.InnerHtml = new BootstrapIcon(model.iconAppend, model.iconAppendIsWhite).ToHtmlString();
addOnAppendIcon = addOn.ToString();
}
if (!string.IsNullOrEmpty(model.iconPrependCustomClass))
{
appendPrependContainer.AddOrMergeCssClass("input-prepend");
var i = new TagBuilder("i");
i.AddCssClass(model.iconPrependCustomClass);
addOn.InnerHtml = i.ToString(TagRenderMode.Normal);
addOnPrependIcon = addOn.ToString();
}
if (!string.IsNullOrEmpty(model.iconAppendCustomClass))
{
appendPrependContainer.AddOrMergeCssClass("input-append");
var i = new TagBuilder("i");
i.AddCssClass(model.iconAppendCustomClass);
addOn.InnerHtml = i.ToString(TagRenderMode.Normal);
addOnAppendIcon = addOn.ToString();
}
appendPrependContainer.InnerHtml = addOnPrependButtons + addOnPrependIcon + addOnPrependString + "{0}" + addOnAppendString + addOnAppendIcon + addOnAppendButtons;
combinedHtml = appendPrependContainer.ToString(TagRenderMode.Normal) + "{1}{2}";
}
var helpText = model.helpText != null ? model.helpText.ToHtmlString() : string.Empty;
var validationMessage = "";
if (model.displayValidationMessage && html.ValidationMessage(model.htmlFieldName) != null )
{
var validation = html.ValidationMessage(model.htmlFieldName).ToHtmlString();
validationMessage = new BootstrapHelpText(validation, model.validationMessageStyle).ToHtmlString();
//.........这里部分代码省略.........
示例4: RenderTextBox
public static HtmlString RenderTextBox(HtmlHelper html, TextBoxModel model, bool isPassword)
{
var combinedHtml = "{0}{1}{2}";
model.htmlAttributes.MergeHtmlAttributes(html.GetUnobtrusiveValidationAttributes(model.htmlFieldName, model.metadata));
if (!string.IsNullOrEmpty(model.id))
model.htmlAttributes.Add("id", model.id);
if (!string.IsNullOrEmpty(model.placeholder))
model.htmlAttributes.Add("placeholder", model.placeholder);
if (model.size != Size._NotSet)
model.htmlAttributes.AddOrMergeCssClass("class", $"input-{model.size.ToName()}");
model.htmlAttributes.AddOrMergeCssClass("class", "form-control");
var input = isPassword
? html.Password(model.htmlFieldName, null, model.htmlAttributes.FormatHtmlAttributes()).ToHtmlString()
: html.TextBox(model.htmlFieldName, model.value, model.format, model.htmlAttributes.FormatHtmlAttributes())
.ToHtmlString();
// account for appendString, prependString, and AppendButtons
if (!string.IsNullOrEmpty(model.prependString) || !string.IsNullOrEmpty(model.appendString) ||
model.iconPrepend != Icons._not_set
|| model.iconAppend != Icons._not_set || !string.IsNullOrEmpty(model.iconPrependCustomClass) ||
!string.IsNullOrEmpty(model.iconAppendCustomClass))
{
var appendPrependContainer = new TagBuilder("div");
appendPrependContainer.AddOrMergeCssClass("input-group");
appendPrependContainer.AddOrMergeCssClass("mar-btm");
var addOnPrependString = "";
var addOnAppendString = "";
var addOnPrependIcon = "";
var addOnAppendIcon = "";
var addOn = new TagBuilder("span");
addOn.AddCssClass("input-group-addon");
if (!string.IsNullOrEmpty(model.prependString))
{
addOn.InnerHtml = model.prependString;
addOnPrependString = addOn.ToString();
}
if (!string.IsNullOrEmpty(model.appendString))
{
addOn.InnerHtml = model.appendString;
addOnAppendString = addOn.ToString();
}
if (model.iconPrepend != Icons._not_set)
{
addOn.InnerHtml = new Icon(model.iconPrepend, model.iconPrependIsWhite).ToHtmlString();
addOnPrependIcon = addOn.ToString();
}
if (model.iconAppend != Icons._not_set)
{
addOn.InnerHtml = new Icon(model.iconAppend, model.iconAppendIsWhite).ToHtmlString();
addOnAppendIcon = addOn.ToString();
}
if (!string.IsNullOrEmpty(model.iconPrependCustomClass))
{
var i = new TagBuilder("i");
i.AddCssClass(model.iconPrependCustomClass);
addOn.InnerHtml = i.ToString(TagRenderMode.Normal);
addOnPrependIcon = addOn.ToString();
}
if (!string.IsNullOrEmpty(model.iconAppendCustomClass))
{
var i = new TagBuilder("i");
i.AddCssClass(model.iconAppendCustomClass);
addOn.InnerHtml = i.ToString(TagRenderMode.Normal);
addOnAppendIcon = addOn.ToString();
}
appendPrependContainer.InnerHtml = addOnPrependIcon + addOnPrependString + "{0}" + addOnAppendString +
addOnAppendIcon;
combinedHtml = appendPrependContainer.ToString(TagRenderMode.Normal) + "{1}{2}";
}
var helpText = model.helpText != null ? model.helpText.ToHtmlString() : string.Empty;
var validationMessage = "";
if (model.displayValidationMessage)
{
var validation = html.ValidationMessage(model.htmlFieldName).ToHtmlString();
validationMessage = new HelpText(validation, model.validationMessageStyle).ToHtmlString();
}
var htmlTextBox = string.Format(combinedHtml, input, helpText, validationMessage);
TagBuilder inputWrapper = null;
if (!string.IsNullOrEmpty(model.inputElementWrapper))
{
//.........这里部分代码省略.........