Monday 1 January 2018

ASP.Net MVC: ViewData Tutorial with example

ASP.Net MVC: ViewData Tutorial with example
Description:

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.
Controller:

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>


This entry was posted in :

0 comments:

Post a Comment