Theory :- PASSING DATA FROM A CONTROLLER TO A VIEW IN MVC In an ASP.NET MVC application, a controller typically performs the business logic of the application and needs to return the result to the user through a view. You can use the following objects to pass data between controller and view: Ø ViewData Ø ViewBag Ø TempData ViewData · Passes data from a controller to a view. · Is a dictionary of objects that is derived from the ViewDataDictionary class. · Some of the characteristics of ViewData are as follows: · The life of a ViewData object exists only during the current request. · The value of ViewData becomes null if the request is redirected. · ViewData requires typecasting when you use complex data type to avoid error. The general syntax of ViewData is as follows: ViewData[“<Key>”] = <Value>; where, Ø Key : Is a String value to identify the object present in ViewData. Ø Value : Is the object present...
Comments
Post a Comment