The ViewBag
is available in the View without you passing it in. If you add something to ViewBag
in the Controller, it will be available in the View.
//Controller
public ActionResult Test()
{
ViewBag.Message = "Hello World";
return View();
}
//In The View
@if(!string.IsNullOrEmpty(ViewBag.Message))
{
<p>ViewBag.Message</p>
}