我正在尝试更新特定ID的数据列表,并且列表视图有3列。假设我在列表视图中有6行,第一列的名称与列表视图中6条记录的名称相同。第二列是问题,六个问题都不同。下一列是“ Vision”,这是一个下拉列表,在初始加载时,当前记录将是默认值。该下拉列表将是可编辑的,并且每个问题列都有基于VisionId附带的QuestionId的不同下拉列表集。我不知道该怎么做,请帮忙。预先感谢
这是我的控制器上的代码EditAssessment。这会将我的列表视图加载到我的剃须刀页面上。
public IActionResult EditAssessment(int? id)
{
if (id == null)
{
return NotFound();
}
IQueryable<Assessment> data =
_context.Assessment
.Include(a => a.AsIs)
.Include(a => a.Question)
.Include(a => a.Vision)
.Where(a => a.ProfileId == id);
if (dataDividendToolContext == null)
{
return NotFound();
}
ViewData["Vision"] = new SelectList(_context.MaturityLevel,
"Description", "Description");
return View(data .ToList());
}
这是我的剃刀视图代码,我不知道如何将Question作为动态参数传递给Dropdownlist。请注意,列表视图上的问题都是不同的,因此下拉列表应具有不同的数据集。
<table class="table">
<thead>
<tr>
<th>
Profile
</th>
<th>
Question
</th>
<th>
Vision
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Profile.ProfileName)
</td>
<td>
@Html.DisplayFor(modelItem =>
item.Question.QuestionDescription)
</td>
<td>
<select asp-for="@item.Vision" class="form-control" asp-
items="ViewBag.Vision"></select>
</td>
</tr>
}
</tbody>
</table>