You just need to create an extension method on HtmlHelper
:
public static class MyHtmlHelpers
{
public static MvcHtmlString MyTextBoxFor<TModel, TProperty>(
this HtmlHelper<TModel> helper,
Expression<Func<TModel, TProperty>> expression)
{
return helper.TextBoxFor(expression, new { @class = "txt" });
}
}
Then in your view you can use it as:
@Html.MyTextBoxFor(model => model.FirstName)
Note: Don't forget to @using
the namespace of MyHtmlHelpers
if your views.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…