ASP.NET MVC Flashcards
What is ASP.NET MVC?
ASP.NET MVC is a web development framework from Microsoft that is based on the MVC architectural design pattern.
What are the Core features of ASP.NET MVC?
Clear separation of application concerns (Presentation and Business Logic). It reduces complexity that makes it ideal for large scale applications where multiple teams are working.
It provides extensive support for URL Routing
It supports for Test Driven Development (TDD) approach. In ASP.NET Web Forms, testing support is dependent on a Web Server but ASP.NET MVC makes it independent of a Web Server, database or any other classes.
Support for existing ASP.NET features like membership and roles, authentication and authorisation, provider model and caching etc.
What is Routing in ASP.NET MVC?
ASP.NET MVC framework uses a routing engine that maps URLs to controller classes.
We can define routing rules for the engine, so that it can map incoming request URLs to the appropriate controller.
When a user types a URL in a browser window the routing engine uses routing rules that are defined in the Global.asax file in order to parse the URL and find out the path of corresponding controller.
What is the difference between ViewData, ViewBag and TempData?
Both ViewBag and ViewData are used to communicate between controller and corresponding view but this communication is only for a server call, it becomes null if redirect occurs.
So, in short, it’s a mechanism to maintain state between controller and corresponding view.
What is the difference between ViewData, ViewBag and TempData?
Both ViewBag and ViewData are used to communicate between the controller and corresponding view but this communication is only for a server call, it becomes null if redirect occurs.
TempData allows us to persisting data for the duration of single subsequent request. It is usually used to stored only one time messages like validation messages, error messages etc.
What is ViewData and when is it used?
ViewData is a dictionary object that is derived from ViewDataDictionary class.
ViewData is a property of ControllerBase class.
It is used to pass data from controller to corresponding view.
The data is only available during the current request. If redirection occurs then it’s value becomes null.
Typecasting is required for getting the data and need to check for null values to avoid error.
What is ViewBag and when is it used?
ViewBag is a dynamic property
Basically it is a wrapper around the ViewData.
It is used to pass data from controller to corresponding view.
The data is only available during the current request. If redirection occurs then it’s value becomes null.
It doesn’t required typecasting for getting data.
What is TempData and when is it used?
TempData is a dictionary object that is derived from TempDataDictionary class and is stored in short lives session.
It is used to pass data from the current request to a subsequent request (means redirecting from one page to another).
It’s life is very short and lies only till the target view is fully loaded.
It is usually used to store only one time messages like error messages, validation messages.
Typecasting is required for getting the data and need to check for null values to avoid error.
What is Session and when is it used?
Session is a property of the Controller class whose type is HttpSessionStateBase.
It is also used to pass data within the application.
Session is valid for all requests, not for a single redirect.
Typecasting is required for getting the data and need to check for null values to avoid error.