Skip to content

Instantly share code, notes, and snippets.

@andreabalducci
Forked from anonymous/htmlhelper.cs
Created December 17, 2012 10:48
Show Gist options
  • Save andreabalducci/4317384 to your computer and use it in GitHub Desktop.
Save andreabalducci/4317384 to your computer and use it in GitHub Desktop.
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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment