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

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

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

问题

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

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

我尝试将 'autocomplete=off' 添加到 标签中(请参见下面的代码),但它仍然自动填充。

  1. @page
  2. @using FarmersPortal.Areas.Identity.Pages.Account.Manage;
  3. @model EmailModel
  4. @{
  5. ViewData["Title"] = "Manage Email";
  6. ViewData["ActivePage"] = ManageNavPages.Email;
  7. }
  8. <style>
  9. body {
  10. background-image: url('http://10.48.1.215/PORTAL/hero-range-1.jpg');
  11. height: 100%;
  12. background-position: center;
  13. background-repeat: no-repeat;
  14. background-size: cover;
  15. }
  16. </style>
  17. <h3 style="color:white">@ViewData["Title"]</h3>
  18. <partial name="_StatusMessage" for="StatusMessage" />
  19. <div class="row">
  20. <div class="col-md-6">
  21. <form id="email-form" method="post">
  22. <div asp-validation-summary="All" class="text-danger"></div>
  23. <div class="form-floating input-group">
  24. <input asp-for="Email" class="form-control" disabled />
  25. <div class="input-group-append">
  26. <span class="h-100 input-group-text text-success font-weight-bold">✓</span>
  27. </div>
  28. <label asp-for="Email" class="form-label"></label>
  29. </div>
  30. <div class="form-floating">
  31. <input asp-for="Input.NewEmail" class="form-control" autocomplete="off" aria-required="true" />
  32. <label asp-for="Input.NewEmail" class="form-label"></label>
  33. <span asp-validation-for="Input.NewEmail" class="text-danger"></span>
  34. </div>
  35. <button id="change-email-button" type="submit" asp-page-handler="ChangeEmail" class="w-100 btn btn-lg btn-primary">Change email</button>
  36. </form>
  37. </div>
  38. </div>
  39. @section Scripts {
  40. <partial name="_ValidationScriptsPartial" />
  41. }
英文:

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.

  1. @page
  2. @using FarmersPortal.Areas.Identity.Pages.Account.Manage;
  3. @model EmailModel
  4. @{
  5. ViewData[&quot;Title&quot;] = &quot;Manage Email&quot;;
  6. ViewData[&quot;ActivePage&quot;] = ManageNavPages.Email;
  7. }
  8. &lt;style&gt;
  9. body {
  10. background-image: url(&#39;http://10.48.1.215/PORTAL/hero-range-1.jpg&#39;);
  11. height: 100%;
  12. background-position: center;
  13. background-repeat: no-repeat;
  14. background-size: cover;
  15. /* background-color: white;*/
  16. }
  17. &lt;/style&gt;
  18. &lt;h3 style=&quot;color:white&quot;&gt;@ViewData[&quot;Title&quot;]&lt;/h3&gt;
  19. &lt;partial name=&quot;_StatusMessage&quot; for=&quot;StatusMessage&quot; /&gt;
  20. &lt;div class=&quot;row&quot;&gt;
  21. &lt;div class=&quot;col-md-6&quot;&gt;
  22. &lt;form id=&quot;email-form&quot; method=&quot;post&quot;&gt;
  23. &lt;div asp-validation-summary=&quot;All&quot; class=&quot;text-danger&quot;&gt;&lt;/div&gt;
  24. &lt;div class=&quot;form-floating input-group&quot;&gt;
  25. &lt;input asp-for=&quot;Email&quot; class=&quot;form-control&quot; disabled /&gt;
  26. &lt;div class=&quot;input-group-append&quot;&gt;
  27. &lt;span class=&quot;h-100 input-group-text text-success font-weight-bold&quot;&gt;✓&lt;/span&gt;
  28. &lt;/div&gt;
  29. &lt;label asp-for=&quot;Email&quot; class=&quot;form-label&quot;&gt;&lt;/label&gt;
  30. &lt;/div&gt;
  31. &lt;div class=&quot;form-floating&quot;&gt;
  32. &lt;input asp-for=&quot;Input.NewEmail&quot; class=&quot;form-control&quot; autocomplete=&quot;off&quot; aria-required=&quot;true&quot; /&gt;
  33. &lt;label asp-for=&quot;Input.NewEmail&quot; class=&quot;form-label&quot;&gt;&lt;/label&gt;
  34. &lt;span asp-validation-for=&quot;Input.NewEmail&quot; class=&quot;text-danger&quot;&gt;&lt;/span&gt;
  35. &lt;/div&gt;
  36. &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;
  37. &lt;/form&gt;
  38. &lt;/div&gt;
  39. &lt;/div&gt;
  40. @section Scripts {
  41. &lt;partial name=&quot;_ValidationScriptsPartial&quot; /&gt;
  42. }

答案1

得分: 1

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

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

  1. <input asp-for="Input.NewEmail" class="form-control" autocomplete="off" aria-required="true" />

来输入Input.NewEmail的值,我认为在渲染此视图之前,Input.NewEmail已经有了这个值,asp-for将获取此值并在输入标签中设置value="xxx"属性。

所以如果你不想显示该值,你可以使用name属性而不是asp-for,将你的代码更改为:

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

  1. &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:

  1. &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:

确定