c# - 如何保存超过 3 个 html 的数据
问题描述
您好,我有一个带有多个 html/input 标签的表单。像这样:
<form class="form-group">
<div class="body table-responsive">
<table class="table m-b-0">
<thead>
<tr>
<th>Name</th>
<th>age</th>
<th>phone number</th>
<th>ID</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>@item.name</td>
<td>
<input type="text" name="" id="" value=""
class="bordered">
</td>
<td>
<input type="text" name="" id="" value=""
class="bordered">
</td>
<td>
<input type="text" name="" id="" value=""
class="bordered">
</td>
</tr>
}
</tbody>
</table>
</div>
</form>
我还没有命名或标识它们,因为我知道有一种方法可以填充所有输入并在按下提交或按钮时同时保存它们,我只是不知道如何。
我是否需要在 上添加标签或属性以便能够在按下时同时保存所有输入?
解决方案
您必须为每个输入分配名称并添加一个提交按钮。当您单击提交时,用户输入将使用给定的方法发送到服务器。
<form method="post" class="form-group">
<div class="body table-responsive">
<table class="table m-b-0">
<thead>
<tr>
<th>Name</th>
<th>age</th>
<th>phone number</th>
<th>ID</th>
</tr>
</thead>
<tbody>
@{
var i = 0;
foreach (var item in Model) {
<tr>
<td>@item.name</td>
<td>
<input type="text" name="input1_@i" id="" value=""
class="bordered">
</td>
<td>
<input type="text" name="input2_@i" id="" value=""
class="bordered">
</td>
<td>
<input type="text" name="input3_@i" id="" value=""
class="bordered">
</td>
</tr>
}
}
</tbody>
</table>
</div>
<button type="submit">Submit</button>
</form>
或者你可以监听提交事件并自己处理。
$('form').submit(function(e) {
e.preventDefault();
// you can get the input data from 'this' (form element)
// here comes your validation and server call
});
推荐阅读
- java - 在从 sqlite DB 获取的列表视图中显示粗体字母
- android - Flutter日历添加事件'package:flutter_calendar_carousel/classes/event.dart':断言失败:第15行pos 15:'date!= null':不正确
- c# - Linq:根据另一个列表分组和求和
- python - Python:如何在类中可靠地清理 httpx 或请求会话对象?
- javascript - 如何在 html 中使用 nodejs 网络?
- php - 是否可以从 URL 中删除请求查询参数?拉拉维尔
- java - 为 AWS Fargate Springboot 应用程序热重载 S3 上可用的配置
- r - R 中使用 aov_ez 的混合模型方差分析(包:afex)
- flutter - Flutter Http 请求可在 broser 上使用,但无法在 Android 设备上运行
- elasticsearch - 通过 LocalDate.MAX 搜索时 Elasticsearch 失败如何解决?