‘newEmail’ 框与身份一起提供,自动填充且无法停止

huangapple go评论70阅读模式
英文:

'newEmail' box that comes with identity is autopopulating and I can't stop it

问题

我已经创建了一个网站并包含了用于登录的身份验证。在“管理您的帐户”页面上,新的电子邮件框不断自动填充,我无法弄清楚如何停止它。

‘newEmail’ 框与身份一起提供,自动填充且无法停止

我尝试将 '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.

‘newEmail’ 框与身份一起提供,自动填充且无法停止

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[&quot;Title&quot;] = &quot;Manage Email&quot;;
ViewData[&quot;ActivePage&quot;] = ManageNavPages.Email;
}
&lt;style&gt;
body {
background-image: url(&#39;http://10.48.1.215/PORTAL/hero-range-1.jpg&#39;);
height: 100%;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
/*        background-color: white;*/
}
&lt;/style&gt;
&lt;h3 style=&quot;color:white&quot;&gt;@ViewData[&quot;Title&quot;]&lt;/h3&gt;
&lt;partial name=&quot;_StatusMessage&quot; for=&quot;StatusMessage&quot; /&gt;
&lt;div class=&quot;row&quot;&gt;
&lt;div class=&quot;col-md-6&quot;&gt;
&lt;form id=&quot;email-form&quot; method=&quot;post&quot;&gt;
&lt;div asp-validation-summary=&quot;All&quot; class=&quot;text-danger&quot;&gt;&lt;/div&gt;
&lt;div class=&quot;form-floating input-group&quot;&gt;
&lt;input asp-for=&quot;Email&quot; class=&quot;form-control&quot; disabled /&gt;
&lt;div class=&quot;input-group-append&quot;&gt;
&lt;span class=&quot;h-100 input-group-text text-success font-weight-bold&quot;&gt;✓&lt;/span&gt;
&lt;/div&gt;
&lt;label asp-for=&quot;Email&quot; class=&quot;form-label&quot;&gt;&lt;/label&gt;
&lt;/div&gt;
&lt;div class=&quot;form-floating&quot;&gt;
&lt;input asp-for=&quot;Input.NewEmail&quot; class=&quot;form-control&quot; autocomplete=&quot;off&quot; aria-required=&quot;true&quot; /&gt;
&lt;label asp-for=&quot;Input.NewEmail&quot; class=&quot;form-label&quot;&gt;&lt;/label&gt;
&lt;span asp-validation-for=&quot;Input.NewEmail&quot; class=&quot;text-danger&quot;&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;button id=&quot;change-email-button&quot; type=&quot;submit&quot; asp-page-handler=&quot;ChangeEmail&quot; class=&quot;w-100 btn btn-lg btn-primary&quot;&gt;Change email&lt;/button&gt;
&lt;/form&gt;
&lt;/div&gt;
&lt;/div&gt;
@section Scripts {
&lt;partial name=&quot;_ValidationScriptsPartial&quot; /&gt;
}

答案1

得分: 1

asp-for设置idname和与验证相关的属性,还会在视图中设置输入元素的值,如果模型中已经有值的话。

根据你的代码,你正在使用:

<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:

&lt;input asp-for=&quot;Input.NewEmail&quot; class=&quot;form-control&quot; autocomplete=&quot;off&quot; aria-required=&quot;true&quot; /&gt;

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=&quot;xxx&quot; 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:

&lt;input name=&quot;Input.NewEmail&quot; class=&quot;form-control&quot; autocomplete=&quot;off&quot; aria-required=&quot;true&quot; /&gt;

Then when render this view, Input tag will show nothing.

huangapple
  • 本文由 发表于 2023年6月1日 19:54:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76381599.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定