0

I have a textbox that insert only number and add comma separator in it.

I use this code in view

  @Html.TextBoxFor(m => m.TurnRatingCost, null, new { @class = "form-control",onkeyup= "javascript:this.value=Comma(this.value);", onkeydown = "return ValidateNumber(event);" })

it is ok, but i want to convert this to custom TextboxFor with htmlHelper .

ar.gorgin
  • 4,765
  • 12
  • 61
  • 100

1 Answers1

0

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)
    {
       // Your Custom code
    }
}

Then in your view you can use it as:

@Html.MyTextBoxFor(model => model.FirstName) 

Note: Don't forget to @using the namespace of MyHtmlHelpers in your views

Dhrumil shah
  • 611
  • 4
  • 23