Skip to content

Instantly share code, notes, and snippets.

@EdCharbeneau
Last active December 24, 2015 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EdCharbeneau/6828273 to your computer and use it in GitHub Desktop.
Save EdCharbeneau/6828273 to your computer and use it in GitHub Desktop.
Extending the TextBoxFor helper
public static MvcHtmlString CustomTextBoxFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TProperty>> expression, string customData)
{
return htmlHelper.CustomTextBoxFor(expression, customData, (IDictionary<string, object>)null);
}
public static MvcHtmlString CustomTextBoxFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper,
Expression<Func<TModel, TProperty>> expression, string customData, object htmlAttributes)
{
IDictionary<string, object> attributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes);
attributes.Add("data-custom", customData);
return htmlHelper.TextBoxFor(expression, new { data_custom = "customData" });
}
@EdCharbeneau
Copy link
Author

Tested & working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment