Display a tooltip with Html helper

15.4k Views Asked by At

I'd like add a tooltip to my razor view like this :

   @Html.Editor("Password", new { Title = "Doit contenir au moins une lettre majuscule, une minuscule, un chiffre et un caractère spécial" }) 

It is not working, If I just change the html helper by the input html tag, it works!!

I need to know :

  1. Where is the cause of this error?
  2. How can I fix it?
1

There are 1 best solutions below

0
On BEST ANSWER

Adding html attributes using Html.EditorFor() and is only supported in MVC-5.1+. If you do have MVC-5.1, then the correct usage is

@Html.EditorFor(m => m.Password, new { htmlAttributes = new { Title = "Doit contenir ... spécial" }, })

Other wise you need to use the @Html.Password() or @Html.PasswordFor() methods

@Html.PasswordFor(m => m.Password, new { Title = "Doit contenir ... spécial"  })

Refer documentation