我已将此操作添加到控制器,并且在“视图”中显示
<p class="text-success">@ViewBag.result<p />
但是在我单击“提交”后,此viewbag消息不可见...
public ActionResult Contact()
{
Contact cn = new Contact();
cn.DateTime = System.DateTime.Now;
return View(cn);
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Contact(Contact contact)
{
if (ModelState.IsValid)
{
ViewBag.result = "Record Inserted Successfully!";
db.Contacts.Add(contact);
db.SaveChanges();
return RedirectToAction("Contact");
}
return View(contact);
}