3
Answers

ViewBag and/or Tempdata not showing

First Last

First Last

4y
935
1
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)