Use of ViewBag in Asp.net MVC
In my previous posts I have explained various topics like Jquery, asp.net, visual studio,C#.Net,Console application
Now in this post, I will explain about Use of ViewBag in Asp.net MVC with appropriate example.
Use of ViewBag in Asp.net MVC
ViewBag are used when you want to transfer temporary small data (which is not included in model) from the controller to the view. The viewBag is a dynamic type property of ControllerBase class which is the base class of all the controllers.You can assign any number of properties and values to ViewBag.
Now open Visual Studio and create MVC project then write below line of code into it.
in controller file
public ActionResult About()
{
ViewBag.Message = "This is ViewBag.";
return View();
}
in .cshtml file
<h3>@ViewBag.Message</h3>
Summary
You can also read about ASP.NET, C#.Net, JQUERY, AJAX, JavaScript
I hope you get an idea about ViewBag in Asp.net MVC.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you liked this post, don’t forget to share this.