JAS
JAS

Reputation: 294

Asp.Net MVC Html Helper Extension

What is the best way to extend Html Helper TextboxFor? Is there a way to reuse the defautl implementation?

Upvotes: 7

Views: 920

Answers (1)

Massimo Zerbini
Massimo Zerbini

Reputation: 3191

You can create your extension methods (in a static class), for example:

public static MvcHtmlString MyTextBoxFor<TModel, TProperty>(this HtmlHelper<TModel> helper, Expression<Func<TModel, TProperty>> expression)
        {
            // call original method
            MvcHtmlString result = InputExtensions.TextBoxFor(helper, expression);
            // do modification to result
            return result;
        }

Upvotes: 4

Related Questions