我的主视图中有一个局部视图,如下所示:
<div id="complaintlist">
@Html.Action("ShowCaseComplaints", "Cases", new { caseid = Model.CasesID })
</div>
这是部分视图:
@model IEnumerable<cummins_db.ViewModels.CaseComplaintsViewModel>
<table width="100%">
<tr>
<th></th>
<th></th>
<th>Complaint Code</th>
<th>Complaint Description</th>
<th>Delete</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.HiddenFor(modelItem => item.CasesID )
</td>
<td>
@Html.HiddenFor(modelItem => item.CaseComplaintID )
</td>
<td>
@Html.DisplayFor(modelItem => item.ComplaintCode )
</td>
<td>
@Html.DisplayFor(modelItem => item.ComplaintType)
</td>
<td>
@Ajax.ActionLink("Delete", "RemoveCodeFromCase", "Cases", new { caseid = item.CasesID, id = item.CaseComplaintID }, null)
</td>
</tr>
}
</table>
此局部视图具有允许用户从局部视图中的模型中删除记录的操作。这是名为 RemoveCodeFromCase 的操作:
public ActionResult RemoveCodeFromCase(int caseid, int id)
{
if (ModelState.IsValid)
{
CaseComplaint c = db.CaseComplaints.Find(id);
db.CaseComplaints.Remove(c);
db.SaveChanges();
var data = (from C in db.CaseComplaints
where C.CasesID == caseid
select new CaseComplaintsViewModel()
{
CasesID = C.CasesID,
CaseComplaintID = C.ComplaintCodeID,
ComplaintCode = C.ComplaintCode.ComplaintCodeName,
ComplaintType = C.ComplaintCode.ComplaintType
}).ToList();
return PartialView("_CaseComplaintCodes", data);
}
return PartialView("_CaseComplaintCodes");
}
我试图了解如何在此操作运行后刷新我的部分视图。
谢谢