/// <summary> /// Bootstrap and HTML 5 Text Box Helper /// </summary> /// <param name="htmlHelper">The HTML helper instance that this method extends.</param> /// <param name="expression">An expression that identifies the object that contains the properties to render.</param> /// <param name="type">The text type to set (text, password, date, tel, email, etc.).</param> /// <param name="title">The HTML 5 'title' attribute to set.</param> /// <param name="placeholder">The HTML 5 'placeholder' attribute to set.</param> /// <param name="isRequired">Whether or not to set the 'required' attribute on this text box.</param> /// <param name="isAutoFocus">Whether or not to set the 'autofocus' attribute on this text box.</param> /// <param name="isDisable">Whether or not to set the 'disable' attribute on this text box.</param> /// <param name="htmlAttributes">An object that contains the HTML attributes to set for the element.</param> /// <returns>An HTML input element with the appropriate type set.</returns> public static MvcHtmlString TextBox5For <TModel, TValue>( this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TValue> > expression, Html5InputTypes type, string title, string placeholder, bool isRequired, bool isAutoFocus, bool isDisable, object htmlAttributes = null) { MvcHtmlString html = default(MvcHtmlString); Dictionary <string, object> attr = new Dictionary <string, object>(); if (htmlAttributes != null) { var attributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes); foreach (var item in attributes) { attr.Add(item.Key, item.Value); } } attr.Add("type", type.ToString()); attr.Add("class", "form-control"); if (!string.IsNullOrEmpty(title)) { attr.Add("title", title); } if (!string.IsNullOrEmpty(placeholder)) { attr.Add("placeholder", placeholder); } if (isAutoFocus) { attr.Add("autofocus", "autofocus"); } if (isRequired) { attr.Add("required", "required"); } if (isDisable) { attr.Add("disabled", ""); } html = InputExtensions.TextBoxFor(htmlHelper, expression, attr); return(html); }
public static MvcHtmlString TextBoxFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TValue> > expression, string title = null, string placeholder = null, bool autofocus = false, bool required = false, Html5InputTypes type = Html5InputTypes.Text, string icon = null, object htmlAttributes = null ) { RouteValueDictionary rvd = new RouteValueDictionary( HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)); rvd.Add("type", type.ToString()); rvd.Add("class", "form-control"); rvd.Add("stype", "text-align: center;"); if (required) { rvd.Add("required", ""); } if (!string.IsNullOrWhiteSpace(title)) { rvd.Add("title", title); } if (!string.IsNullOrWhiteSpace(placeholder)) { rvd.Add("placeholder", placeholder); } if (autofocus) { rvd.Add("autofocus", ""); } if (!string.IsNullOrEmpty(icon)) { } return(InputExtensions.TextBoxFor(htmlHelper, expression, rvd)); }