Last active
December 24, 2015 16:29
-
-
Save EdCharbeneau/6828273 to your computer and use it in GitHub Desktop.
Extending the TextBoxFor helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tested & working