The direct question, it seems, cannot display my viewBag value in the view that the user accesses after the form is completed.
Please advise ... thanks
My ActionResult index simply returns model data.
public ActionResult Index() { var source = _repository.GetByUserID(_applicationUser.ID); var model = new RefModel { test1 = source.test1, }; return View(model); }
My Get Edit "ActionResult, just uses the same model data as Index.
My Post "Change" ActionResult, assigns new values, if any, and redirects to the Index page, but the ViewBag value is not displayed on the Index page
[HttpPost] public ActionResult Edit(RefModell model) { if (ModelState.IsValid) { var source = _repository.GetByUserID(_applicationUser.ID); if (source == null) return View(model); source.test1 = model.test1; _uow.SaveChanges(); @ViewBag.Message = "Profile Updated Successfully"; return RedirectToAction("Index"); } return View(model); }
And in my index view ...
@if(@ViewBag.Message != null) { <div> <button type="button">@ViewBag.Message</button> </div> }
mkell source share