【发布时间】:2021-10-18 19:42:31
【问题描述】:
我的视图中有一个对象列表。在表格中,在某些条件下,我创建行并添加一个按钮。当按下 modal-footer 按钮时,我想将该行的数据传递给我的控制器。我尝试了 ajax 请求和表单,但我无法管理它。到达我的控制器的总是列表的第一个元素。
我的看法:
<table class="table border-bottom dataTable" id="dataTable" width="100%" cellspacing="0" role="grid" aria-describedby="dataTable_info" style="width: 100%;">
<thead>
<tr><th rowspan="1">Saat</th><th rowspan="1">Durum</th></tr>
</thead>
@{int i = 0; }
@foreach (var v in Model)
{
<tbody>
<tr>
@if (v.IsActive == 1)
{
<td>@v.Hour.ToString():@v.Minute.ToString().ElementAt(0)0</td>
<td><p class="blckpassive">Dolu</p></td>
}
else
{
<td>@v.Hour.ToString():@v.Minute.ToString().ElementAt(0)0</td>
<td><p class="blckactive">Boş</p></td>
<td><button type="button" class="btn btn-info" data-toggle="modal" data-target="#exampleModal">Randevu Al</button></td>
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Emin Misiniz?</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
Seçtiğiniz Randevuyu Almak İstiyor Musunuz?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">İptal</button>
<a type="button" href="/Appointment/AddAppointment?hour=@v.Hour" class="btn btn-primary">Evet</a>
</div>
</div>
</div>
</div>
}
</tr>
</tbody>
i++;
}
</table>
控制器:
public IActionResult AddAppointment(int hour)
{
return null;
}
列表中的对象具有小时和分钟变量,它们是 int 并且排序为“9:00,9:30,10:00,10:30...16:00”。
【问题讨论】:
-
v.Hour是该列表中的第一项吗?还是您的意思是Model中的每个v都有一个不同的.Hour,分别为 9、9:30、10... -
表格是否显示了正确的时间,它只是被打破,舔链接?
-
@MenachemHornbacher 显示正确数据的表,模型中的每个 v 都有不同的小时,是的。
-
有趣,列表中的链接是什么。它们都具有相同的值还是仅在提交时才会发生?
-
@MenachemHornbacher 它们都有不同的值,来自 db。在提交时,我需要知道点击了哪个值,所以我需要来自该对象的数据。我也会用它填充数据库。
标签: c# html asp.net-core asp.net-core-mvc