我的控制器方法是
public ActionResult Index(string id = "All")
{
ViewBag.RefType = new SelectList(rep.getReferenceType());
List<Reference> reference = rep.getReference(id);
if (Request.IsAjaxRequest())
return PartialView("_ReferenceList", reference);
else
{
ViewBag.domain = "All";
return View(reference);
}
}
第二种方法调用索引
public ActionResult EditReference(Reference rf, int Dom)
{
Reference rf1 = null;
string dom = "";
if (ModelState.IsValid)
{
rf1 = rep.UpdateReference(rf);
if (Dom == 0)
{
dom = "All";
}
else
{
dom = rf1.Domain;
}
return RedirectToAction("Index", new { id =dom});
}
return View(rf1);
}
我的观点是
@using (Ajax.BeginForm("EditReference", "Reference", new AjaxOptions { HttpMethod = "POST", OnSuccess = "closeDialog()", LoadingElementId = "divLoading" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
Html.RenderPartial("_Reference");
}
问题是一旦对话框关闭,新编辑的数据就不会出现......它显示相同的旧数据......我尝试了另一个功能
function closDlgAndRefresh{
$('.Dialog').dialog('close');
$('.ddlRndrPrtl').val($('.ddlRndrPrtl').val());
$('.ddlRndrPrtl').trigger('change');
}
当我在onSuccess上调用此函数时,它确实会显示数据,但是Index函数被调用两次,我没有做过...一旦从Edit函数调用Index函数而第二次触发下拉时...
答案 0 :(得分:0)
修好了....
忘记在Ajax.BeginForm中添加更新的TargetID
@using (Ajax.BeginForm("EditReference", "Reference", new AjaxOptions { HttpMethod = "POST", LoadingElementId = "divLoading", InsertionMode = InsertionMode.Replace, UpdateTargetId = "DivTbl_Reference" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
Html.RenderPartial("_Reference");
}