Skip to content

Instantly share code, notes, and snippets.

Created December 17, 2012 10:47

Revisions

  1. @invalid-email-address Anonymous created this gist Dec 17, 2012.
    22 changes: 22 additions & 0 deletions htmlhelper.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    public static IHtmlString SkinnedTextBoxFor<TModel, TValue>(this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression, InputStyles styles = InputStyles.Normal, int size = 0)
    {
    var cssClasses = BuildClasses(styles, "input");
    IDictionary<string, object> attrs = new Dictionary<string, object>();
    attrs["class"] = cssClasses;
    if (size > 0)
    attrs["size"] = size;

    string format = null;
    if (typeof (DateTime).IsAssignableFrom(expression.ReturnType))
    {
    attrs["type"] = "date";
    format = "{0:yyyy-MM-dd}";
    }
    else if (typeof (TimeSpan).IsAssignableFrom(expression.ReturnType))
    {
    attrs["type"] = "time";
    format = "{0:hh':'mm}";
    }

    return html.TextBoxFor(expression, format, attrs);
    }