Description:
Controller:
In this example
we explain that how to use ViewData in MVC.or implement functionality of the ViewData
in MVC Razor View.so here we demonstrate that what is ViewData and use of the ViewData
in MVC Razor View.
Generally, ViewData
is derived from the ViewDataDictionary class and is used for the pass value
from controller to view in MVC.ViewData stored Data as an Object in ViewData
and data needs to be casted to its original data and also required to check
NULL processing while retrieving.
public class EmployeeController
: Controller
{
// GET: First
public ActionResult Index()
{
ViewData["Message"]
= "Hello this is the Example of the ViewData!";
return
View();
}
}
View:
<html>
<head>
<title>ASP.Net
MVC: ViewData Tutorial with example</title>
</head>
<body>
<div>
@ViewData["Message"];
</div>
</body>
</html>
0 comments:
Post a Comment