【问题标题】:Webpage form not hitting POST when submitting in Google Chrome在 Google Chrome 中提交时网页表单未点击 POST
【发布时间】:2019-12-21 17:53:27
【问题描述】:

最近几天前,我正在处理一个问题,当我在 Google Chrome 中的表单上点击提交时,后端代码没有被点击,Chrome 继续尝试加载页面。

表格没什么特别的

@using (Html.BeginForm("Login", "Account", FormMethod.Post, new { @class = "login-form" }))
{
    if (!ViewData.ModelState.IsValid)
    {
        <div class="alert alert-danger">@Html.ValidationMessage("error")</div>
    }

    <div class="field-group">
        @Html.LabelFor(i => i.Email)
        @Html.TextBoxFor(i => i.Email, new { required = "required" })
    </div>

    <div class="field-group field-password">
        @Html.LabelFor(i => i.Password)
        @Html.PasswordFor(i => i.Password, new { required = "required" })
        <i class="fas fa-fw fa-eye" id="passwordToggle"></i>
    </div>

    <div class="button-group">
        <input type="submit" value="Log in" />
    </div>
}

但它在我的台式机和笔记本电脑上都发生了,但是当我尝试 FireFox 时它很好。它正在尝试加载页面,因为它在 Chrome 中有微调器,但是当我在方法的开头放置一个断点时,它永远不会被命中。

根据要求添加了部分登录方法

    [HttpPost]
    public ActionResult Login(LoginModel model)
    {
        //List<string> whiteListedEmailAddresses = new List<string>();

        //if (!whiteListedEmailAddresses.Contains(model.Email))
        //    ModelState.AddModelError("error", "Invalid Username and or Password");

        var user = _db.Users.FirstOrDefault(i => i.Email == model.Email);

        if (user == null)
        {
            ModelState.AddModelError("error", "Incorrect email address and/or password. If you are a customer, please switch to the customer site.");
        }

【问题讨论】:

  • 可以显示登录方法的开头吗?
  • 添加登录方式的第一位。
  • +1 我的经历和你完全一样。提交时也没有击中我的控制器动作。浏览器选项卡“旋转”但不执行任何操作。

标签: c# asp.net-mvc forms google-chrome iis


【解决方案1】:

我在 Chrome 中也遇到了这个问题。我的原因:我在单击提交按钮后禁用了它。

对于 Chrome,但不是其他浏览器,点击处理程序似乎在提交处理程序之前触发。出于这个原因,我再也不用回到控制器了。

我的解决方案是在用户单击提交按钮后根本不禁用它。

您的提交按钮是否有可能在您单击后立即被禁用?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-21
    • 1970-01-01
    • 1970-01-01
    • 2023-03-21
    • 2020-12-03
    • 1970-01-01
    • 2013-10-18
    • 1970-01-01
    相关资源
    最近更新 更多