Search code examples
asp.net-mvcangularjsrazorhtml-helper

How to add ng-click to @Html.TextBoxFor in MVC Razor


How can I give my TextBox, ng-click attribute when using Html.TextBoxFor?

@Html.TextBoxFor(model => model.User.Firstname, 
new { 
    @class = "form-control required", 
    placeholder = "نام" 
})

Solution

  • Add ng_click to htmlAttributes object.

    @Html.TextBoxFor(model => model.User.Firstname, new 
    { 
      @class = "form-control required", 
      placeholder = "نام" , 
      ng_click = "yourFunc()" 
    })
    

    *Note : The _ instead of - in ng_click is because C# does not accept -