当控制器中发生错误时,我想将部分视图显示为 jQuery 模式。提交表单后,我需要检查验证,如果验证失败,则在 jQuery 模型弹出窗口中显示部分视图。
编辑.cshtml
<div class="form-actions">
<button type="submit" class="btn btn-primary" >Save changes</button>
@Html.ActionLink("Cancel", "Index", new {id=Model.Contact.Number}, new { @class = "btn " })
</div>
成员控制器.cs
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(Activity activity)
{
try
{
byte[] committeeMemberSpeId = Convert.FromBase64String(activity.Id);
var committeeMember = db.Committee_Member.FirstOrDefault(x => x.Committee_Member_Id == committeeMemberId);
if (ValidateEndDate(activity)) //Show here PartialView("ErrorDetail");
if (ModelState.IsValid)
{
if (committeeMember != null)
{
....
....
db.Entry(committeeMember).State = EntityState.Modified;
db.SaveChanges();
Success("Your information was saved!");
return RedirectToAction("Index", new { id = committeeMember.Customer_Number });
}
}
ViewBag.Roles = TempData["Roles"];
TempData["Roles"] = TempData["Roles"];
return View(activity);
}
catch (Exception exception)
{
Elmah.ErrorSignal.FromCurrentContext().Raise(exception);
PartialView("ErrorDetail");
}
}
我们怎么能做到这一点?