over 9 years ago
There are following four ways to pass data from controller to view in Asp .Net MVC:-
Overview:
Let us see them in more detail:
It is a dictionary object introduced in MVC 1.0. It is used to pass data from controller to the view. It's life cycle is during the current request only. It requires typecasting for retrieving data and null value check inorder to avoid error.
Example:
It is a dynamic property of ControllerBase class introduced in MVC 3.0. It is used to pass data from controller to the view. It's life cycle is during the current request only. It does not requires typecasting for retrieving data.
Example:
It is a dictionary object introduced in MVC 1.0 used to pass data from one page to another (i.e. current request to subsequent request). It's life cycle is very short, lives till the target view is fully loaded. It requires typecasting for retrieving data and null value check inorder to avoid error.Mostly used to store error messages, validation messages,etc.
Example:
It is a property of Controller class used to pass data within the ASP.NET MVC application. It's life cycle depends on its expiration time and is valid for all requests, not for a single redirect. It requires typecasting for retrieving data and null value check inorder to avoid error.
0 Comment(s)