Description:
Controller:
In this example
we explain that how to use ViewBag in MVC.or implement functionality of the ViewBag
in MVC Razor View.so here we demonstrate that what is ViewBag and use of the ViewBag
in MVC Razor View.
Generally, ViewBag
is the dynamic property of the C# 4.0 dynamic features. ViewBag is used for the
passing value from controller to view and no need of casting data.it is only
available on current request.
public class EmployeeController
: Controller
{
// GET: First
public ActionResult Index()
{
ViewBag["Message"]
= "Hello this is the Example of the ViewBag!";
return
View();
}
}
View:
<html>
<head>
<title>ASP.Net
MVC: ViewBag Tutorial with example</title>
</head>
<body>
<div>
@ViewBag["Message"];
</div>
</body>
</html>
0 comments:
Post a Comment