Viewbag in mvc

What is ViewBag?

In general, ViewBag is a way to pass data from the controller to the view. It is a type object and is a dynamic property under the controller base class. Compared to ViewData, this works similarly but is known to be a bit slower and was introduced in ASP.NET MVC.

public ActionResult Index()
        {
            ViewBag.title = "Title";
            return View();
        }

To display these properties in view.

<h1>@ViewBag.title</h1>

2020-01-31