How to disable autocomplete in MVC Html Helper
Solution 1:
Try this:
<%= Html.TextBoxFor(
model => model.date,
new { @class = "aDatePicker", autocomplete = "off" }
)%>
It will generate markup that is close to the following:
<input type="text" id="date" name="date" class="aDatePicker" autocomplete="off" />
Solution 2:
Couple of points
-
If you've more or less already written the site and you don't want to go back and modify all your cshtml to disable autocomplete (we would have had to go back and change hundreds of lines of code throughout the site), you can disable it via Javascript with a ready handler, like so:
//Disable autocomplete throughout the site $(document).ready(function() { $("input:text,form").attr("autocomplete","off"); })
From what I've read you need to disable it at both the form and the textbox level in order for it to work on all versions of Firefox and IE.