c# - .NET MVC - 在文本框中按 Enter 键未提交表单
问题描述
我有一个非常简单的表格,如下所示。
@using (Html.BeginForm())
{
...
@Html.TextBoxFor(x => x.Input);
...
<button type="submit">Submit</button>
}
在文本字段中按 Enter 键不会提交表单。我想知道是否有不涉及任何 JavaScript 的解决方案。因为当我在网上搜索时,有人对文本框的这种“默认”行为感到恼火,想要禁用 Enter 键...
也许它与“按钮”标签有关?我尝试将其更改为“输入”标签。但是按 Enter 仍然不起作用。呈现的 HTML 对我来说看起来很正常:
<form action="/[ControllerName]/[ActionName]/" method="post" novalidate="novalidate">
...
<input id="Input1" name="Input" type="text" value="" aria-required="true">
...
<button type="submit">Submit</button>
...
</form>
解决方案
Enter 键将始终提交页面上的第一个 HTML 表单。确保您的 HTML 中没有隐藏其他表单元素。
推荐阅读
- python - 重新采样数据帧,插入 NaN 并返回数据帧
- laravel - 使用 Sendinblue 从 Laravel 应用程序发送数据
- javascript - formik 组件正在将文本类型的受控输入更改为不受控制
- android - 如何使用 Toothpick 对 android ViewModels 使用构造函数注入
- reactjs - 条件反应属性
- java - Java DerInputStream.getLength():lengthTag=109
- json - 如何以良好的格式查看 JSON 文件?
- python - 如何在另一个模型中解析和序列化抽象用户?
- twilio - Twilio Video - 跟踪启用/禁用事件未触发
- visual-studio-code - Visual Studio Code 已导入与笔记本电脑主要用户关联的所有文件夹,