不需要的自动填充建议ASP.NET MVC-5 Razor

时间:2017-08-25 20:03:44

标签: asp.net asp.net-mvc razor asp.net-mvc-5

它显示了一些不受欢迎的autocomplete建议 我认为这些建议来自 UserName 文字字段 但我没有找到任何理由提出这些建议。

型号代码:

    [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; }

Razor查看:

<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

我不想要这样的建议 请帮助我解决这个问题。

非常感谢

1 个答案:

答案 0 :(得分:0)

从这个网站,也许这是你的问题,自动完成应该可以解决问题,但是如果整个页面都是通过XHTML进行渲染,那么你需要这样的东西。

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

.autocomplete=”off”不是XHTML Transitional的有效标记,它是一种常见的DOCTYPE。使用它来保持虚拟标记

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”);
        }
    }
}