ViewBag or ViewData (“in short, ViewBag and Viewdata are temporary placeholders to store some value valid for that request only) is nothing but an object or variable whose value is generally set in the Controller action method (however it can also be set at other places like View). To write their values, simply call them as if we call any other variable.
To store data into them, we can use below syntax
@{ ViewBag.Title = "Index"; ViewData["MyName"] = "Sheo Narayan"; }
To write their values, call them as if you are calling any variables in Razor syntax.
<h2>ViewBag | ViewData</h2>Views: 16214 | Post Order: 22
@ViewBag.Title <p> @ViewData["MyName"] </p>