[HttpPost] public ActionResult Form(NewsModel model) { if (ModelState.IsValid) { if (model.Id == 0) { cmd.Add(model); } else { cmd.Update(model.Id, model); } ViewBag.Msg = "添加成功!"; ViewBag.ReturnUrl = "/News/List"; } return View(); }
<script type="text/javascript"> $(document).ready(function () { if ('@ViewBag.Msg' != null && '@ViewBag.Msg' != "") { if (confirm('@ViewBag.Msg' + ',是否继续添加')) { window.location.href = 'Form'; } else { window.location.href = '@ViewBag.ReturnUrl'; } } }); </script>
需要引JS包