2017-08-25 91 views
0

它顯示了一些不需要的autocomplete建議。
我覺得那些建議來自UserName文本字段。
但我沒有找到任何理由這些建議。
不需要的自動填充建議ASP.NET MVC-5 Razor

型號代碼:

[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)] 
    [Required(ErrorMessage = "Birth Date is Reqired")] 
    [DataType(DataType.DateTime)] 
    [Display(Name = "Birth Date")] 
    public DateTime BirthDate { get; set; } 

剃刀檢視:

<div class="container jumbotron" style="background-color:whitesmoke"> 
<div class="row"> 
    <div class="col-md-4" style="margin-left: 400px; margin-top:30px"> 
     <section id="loginForm"> 
      @Html.ValidationSummary(true) 
      @using (Html.BeginForm("Registration", "SignUp", FormMethod.Post, new { enctype = "multipart/form-data" })) 
      { 
       <div class="form-group"> 
        @Html.LabelFor(m => m.FirstName) 
        @Html.TextBoxFor(m => m.FirstName, new {@class = "form-control"}) 
        @Html.ValidationMessageFor(m => m.FirstName) 
       </div> 

       <div class="form-group"> 
        @Html.LabelFor(m => m.LastName) 
        @Html.TextBoxFor(m => m.LastName, new {@class = "form-control"}) 
        @Html.ValidationMessageFor(m => m.LastName) 
       </div> 

       <div class="form-group"> 
        @Html.LabelFor(m => m.UserName) 
        @Html.TextBoxFor(m => m.UserName, new {@class = "form-control"}) 
        @Html.ValidationMessageFor(m => m.UserName) 
       </div> 

       <div class="form-group"> 
        @Html.LabelFor(m => m.EmailAddress) 
        @Html.TextBoxFor(m => m.EmailAddress, new {@class = "form-control"}) 
        @Html.ValidationMessageFor(m => m.EmailAddress) 
       </div> 
       <div class="form-group"> 
        @Html.LabelFor(m => m.BirthDate) 
        <input class="form-control" value="yyyy-MM-dd" name="BirthDate" type="text" id="BirthDate" autocomplete="off"> 
        @Html.ValidationMessageFor(m => m.BirthDate) 
       </div> 

       <div class="form-group"> 
        @Html.LabelFor(m => m.PassWord) 
        @Html.PasswordFor(m => m.PassWord, new {@class = "form-control"}) 
        @Html.ValidationMessageFor(m => m.PassWord) 
       </div> 

       <div class="form-group"> 
        @Html.LabelFor(m => m.VerifyPassWord) 
        @Html.PasswordFor(m => m.VerifyPassWord, new {@class = "form-control"}) 
        @Html.ValidationMessageFor(m => m.VerifyPassWord) 
       </div> 

       <div class="form-group"> 
        @Html.LabelFor(m => m.VersityId) 
        @Html.TextBoxFor(m => m.VersityId, new {@class = "form-control"}) 
        @Html.ValidationMessageFor(m => m.VersityId) 
       </div> 

       <div class="form-group"> 
        @Html.LabelFor(m => m.PhoneNumber) 
        @Html.TextBoxFor(m => m.PhoneNumber, new {@class = "form-control"}) 
        @Html.ValidationMessageFor(m => m.PhoneNumber) 
       </div> 

       <div class="form-group"> 
        @Html.LabelFor(m => m.Address) 
        @Html.TextAreaFor(m => m.Address, new {@class = "form-control"}) 
        @Html.ValidationMessageFor(m => m.Address) 
       </div> 

       <div class="form-group"> 
        <input id="ImageUpload" type="file" name="ImageUpload" /> 
       </div> 

       <button type="submit" class="btn btn-primary">Save</button> 
      } 
      <p> 
       @Html.ActionLink("Already Have an Account", "LogIn") 
      </p> 
     </section> 
    </div> 
</div> 

問題視圖(圖像)
Problem indicate by red circle

我不想要這種建議。
請幫我解決這個問題。

非常感謝提前

+0

https://stackoverflow.com/questions/18531437/stop-google-chrome-auto-fill-the-input – adiga

回答

0

從這個網站,也許這是你的問題,自動完成應該做的伎倆,但如果你的整個頁面呈現在XHTML,那麼你就需要像這個。

https://css-tricks.com/snippets/html/autocomplete-off/

.autocomplete=」off」不與XHTML過渡,這是一種常見的DOCTYPE有效的標記。使用此保持vaild標記

if (document.getElementsByTagName) { 

    var inputElements = document.getElementsByTagName(「input」); 

    for (i=0; inputElements[i]; i++) { 

     if (inputElements[i].className && (inputElements[i].className.indexOf(「disableAutoComplete」) != -1)) { 
      inputElements[i].setAttribute(「autocomplete」,」off」); 
     } 
    } 
} 
+0

如何在這裏我可以將此邏輯? –

+0

如果您在開始時使用了xhtml標記,請在您的部分視圖中進行驗證 – thepanch