Disable autocomplete on html helper textbox in MVC

前端 未结 9 1137
太阳男子
太阳男子 2021-01-12 02:17

Ok,

I would in normal asp.net use a theme to turn off autocomplete on all text boxes on an entire site. However i cannot do this on MVC because nothing in the theme

相关标签:
9条回答
  • 2021-01-12 02:42

    ASP.net MVC HTML Attribute: Which is having type="text" Managed by JQUERY code

    @Html.TextBoxFor(model => model.FirstName, new {@id = "txtFirstName"})
    
    
    <script language="javascript" type="text/javascript">
            $(document).ready(function () {
                try {
                    $("input[type='text']").each(function () {
                        $(this).attr("autocomplete", "off-1");
                    });
                }
                catch (e) { }
            });
        
        </script>
    
    0 讨论(0)
  • 2021-01-12 02:45

    AFAIK, you cannot do autocomplete = off with css and it has to be a html attribute and hence there is nothing you can that would affect all Textboxes. One thing you can do is add the attribute to the form like this (it will address all textboxes in the current form)

    Html.BeginForm(action,controller, FormMethod.Post, new { autocomplete="off"})
    

    or create a custom Helper extension method that is similar to BeginForm that adds this html attribute internally.

    0 讨论(0)
  • 2021-01-12 02:52
    @Html.TextBox("Address","",new { @class = "classname", autocomplete = "off" })
    
    0 讨论(0)
提交回复
热议问题