英文:
'newEmail' box that comes with identity is autopopulating and I can't stop it
问题
我已经创建了一个网站并包含了用于登录的身份验证。在“管理您的帐户”页面上,新的电子邮件框不断自动填充,我无法弄清楚如何停止它。
我尝试将 'autocomplete=off' 添加到 标签中(请参见下面的代码),但它仍然自动填充。
@page
@using FarmersPortal.Areas.Identity.Pages.Account.Manage;
@model EmailModel
@{
ViewData["Title"] = "Manage Email";
ViewData["ActivePage"] = ManageNavPages.Email;
}
<style>
body {
background-image: url('http://10.48.1.215/PORTAL/hero-range-1.jpg');
height: 100%;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
</style>
<h3 style="color:white">@ViewData["Title"]</h3>
<partial name="_StatusMessage" for="StatusMessage" />
<div class="row">
<div class="col-md-6">
<form id="email-form" method="post">
<div asp-validation-summary="All" class="text-danger"></div>
<div class="form-floating input-group">
<input asp-for="Email" class="form-control" disabled />
<div class="input-group-append">
<span class="h-100 input-group-text text-success font-weight-bold">✓</span>
</div>
<label asp-for="Email" class="form-label"></label>
</div>
<div class="form-floating">
<input asp-for="Input.NewEmail" class="form-control" autocomplete="off" aria-required="true" />
<label asp-for="Input.NewEmail" class="form-label"></label>
<span asp-validation-for="Input.NewEmail" class="text-danger"></span>
</div>
<button id="change-email-button" type="submit" asp-page-handler="ChangeEmail" class="w-100 btn btn-lg btn-primary">Change email</button>
</form>
</div>
</div>
@section Scripts {
<partial name="_ValidationScriptsPartial" />
}
英文:
I have created a website and included identity for logging in. On the manage your account page, the new email box keeps autopopulating and I can't figure out how to stop it.
I have tried to add the 'autocomplete=off' to the <input> tag (see below code) but it still populates.
@page
@using FarmersPortal.Areas.Identity.Pages.Account.Manage;
@model EmailModel
@{
ViewData["Title"] = "Manage Email";
ViewData["ActivePage"] = ManageNavPages.Email;
}
<style>
body {
background-image: url('http://10.48.1.215/PORTAL/hero-range-1.jpg');
height: 100%;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
/* background-color: white;*/
}
</style>
<h3 style="color:white">@ViewData["Title"]</h3>
<partial name="_StatusMessage" for="StatusMessage" />
<div class="row">
<div class="col-md-6">
<form id="email-form" method="post">
<div asp-validation-summary="All" class="text-danger"></div>
<div class="form-floating input-group">
<input asp-for="Email" class="form-control" disabled />
<div class="input-group-append">
<span class="h-100 input-group-text text-success font-weight-bold">✓</span>
</div>
<label asp-for="Email" class="form-label"></label>
</div>
<div class="form-floating">
<input asp-for="Input.NewEmail" class="form-control" autocomplete="off" aria-required="true" />
<label asp-for="Input.NewEmail" class="form-label"></label>
<span asp-validation-for="Input.NewEmail" class="text-danger"></span>
</div>
<button id="change-email-button" type="submit" asp-page-handler="ChangeEmail" class="w-100 btn btn-lg btn-primary">Change email</button>
</form>
</div>
</div>
@section Scripts {
<partial name="_ValidationScriptsPartial" />
}
答案1
得分: 1
asp-for
设置id
,name
和与验证相关的属性,还会在视图中设置输入元素的值,如果模型中已经有值的话。
根据你的代码,你正在使用:
<input asp-for="Input.NewEmail" class="form-control" autocomplete="off" aria-required="true" />
来输入Input.NewEmail
的值,我认为在渲染此视图之前,Input.NewEmail
已经有了这个值,asp-for
将获取此值并在输入标签中设置value="xxx"
属性。
所以如果你不想显示该值,你可以使用name
属性而不是asp-for
,将你的代码更改为:
<input name="Input.NewEmail" class="form-control" autocomplete="off" aria-required="true" />
然后在渲染此视图时,输入标签将不显示任何内容。
英文:
asp-for
sets the id
, name
and validation related attributes, and it also sets the value of the input element if there is already a value within the model passed to the view.
From your code, You are using:
<input asp-for="Input.NewEmail" class="form-control" autocomplete="off" aria-required="true" />
to input the value of Input.NewEmail
, I think before you render this view, Input.NewEmail
already has the value, asp-for
will get this value and set value="xxx"
attribute in input tag.
So if you don't want show the value, You can just use name property instead of asp-for
, Change your code to:
<input name="Input.NewEmail" class="form-control" autocomplete="off" aria-required="true" />
Then when render this view, Input tag will show nothing.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论