通过单击行上的删除按钮从以下代码中删除列表项ex:4中的第2项后,它在视图中显示1,2,3而不是1,3,4。当我调试视图时它显示正确的值,但是在页面呈现TextBoxFor AeroDromeID显示错误。删除机场按钮也显示正确的值。有人可以帮我解决这个问题。
控制器
[HttpPost]
[MultipleButton(Name = "action", Argument = "DeleteAerodrome")]
public ActionResult DeleteAerodrome(FormCollection fc)
{
int AerodromeID = Int32.Parse(fc["action:DeleteAerodrome"]);
var studentSignoutModel = new StudentSignoutViewModel();
UpdateModel<StudentSignoutViewModel>(studentSignoutModel);
if (studentSignoutModel.Aerodromes.Count > 0)
studentSignoutModel.Aerodromes.RemoveAll(m => m.AerodromeID == AerodromeID);
return View("StudentSignoutStageView", studentSignoutModel);
}
查看
@if (Model.Aerodromes != null && Model.Aerodromes.Any())
{
for (int i = 0; i < Model.Aerodromes.Count; i++)
{
<tr>
<td>@Html.TextBoxFor(a => Model.Aerodromes[i].AerodromeID, new { @class = "form-control"})</td>
<td>@Html.TextBoxFor(a => Model.Aerodromes[i].CloudBase, new { @class = "form-control" })</td>
<td>@Html.TextBoxFor(a => Model.Aerodromes[i].Visibility, new { @class = "form-control" })</td>
<td>@Html.TextBoxFor(a => Model.Aerodromes[i].Wind, new { @class = "form-control" })</td>
<td>@Html.TextBoxFor(a => Model.Aerodromes[i].Crosswind, new { @class = "form-control" })</td>
<td>@Html.TextBoxFor(a => Model.Aerodromes[i].InterTempo, new { @class = "form-control" })</td>
<td>
<input type="submit" id="BtnDelAerodrome" value="@Model.Aerodromes[i].AerodromeID" name="action:DeleteAerodrome" style="font-size:1em" class="btn btn-danger" onclick="return confirm('Are you sure you want to delete the record with AerodromeID = '+ @Model.Aerodromes[i].AerodromeID);" />
</td>
</tr>
}
}
答案 0 :(得分:0)
我认为当我们使用TextBoxFor时,从服务器端渲染时应该存在数据绑定概念的错误。 当我使用模型绑定器的html标签输入时,它工作。 这很容易复制。