First Last

First Last

  • NA
  • 648
  • 72.3k

ViewBag and/or Tempdata not showing

Aug 6 2020 12:39 PM
I hard code values into the ViewBag and TempData but they do NOT show in the view.
 
Why?
I am NOT redirecting, just rendering - returning the view name with a model class.
 
Part of the BlogPublishedSelectionCriteria.cshtml view:
 
@model GbngWebClient.Models.BlogPublishedSelectionCriteriaVM
<h2 class="page-header">Blog Selection Criteria</h2>
@{
Layout = "~/Views/Shared/_LayoutUser.cshtml";
}
<p class="alert alert-danger" id="errorMessage">@TempData["errormessage"]</p>
<p class="alert alert-danger" id="errorMessage2">@ViewBag.errormessage</p>
 
The last part of the action method before returning the view:
 
ViewBag.errormessage = "test";
TempData["errormessage"] = "test";
return View("BlogPublishedSelectionCriteria", blogPublishedSelectionCriteriaVM);

Answers (3)