Q. What is the MVC pattern?
A. MVC(Model View Controller) is an architectural pattern for building applications. ID separates the applications in 3 main component
Model, View and Controller. Model is nothing but the domain object or data, View is the component which contains user interface and Controller do the processing or incoming requests.
Q. What are the Disadvantages of MVC Pattern?
A. Even if this pattern comes with a lot of advantages, there are distinct disadvantages too. Firstly, it is too complex to implement and is not suitable for smaller application; rather, implementing this pattern in such applications will have adverse effects in the application's performance and design.
Q. What is an Action Filter in MVC?
A. In ASP.NET MVC, controllers define action methods that usually have a one-to-one relationship with possible user interactions, such as clicking a link or submitting a form. For example, when the user clicks a link, a request is routed to the designated controller, and the corresponding action method is called.
Sometimes you want to perform logic either before an action method is called or after an action method runs. To support this, ASP.NET MVC provides filters. Filters are custom classes that provide both a declarative and programmatic means to add pre-action and post-action behaviour to controller action methods.
Q. How many types of action filters are there in MVC?
A. ASP.NET MVC provides the following types of action filters:
Authorization filter, which makes security decisions about whether to execute an action method, such as performing authentication or validating properties of the request. The AuthorizeAttribute class is one example of an authorization filter.
Action filter, which wraps the action method execution. This filter can perform additional processing, such as providing extra data to the action method, inspecting the return value, or canceling execution of the action method.
Result filter, which wraps execution of the ActionResult object. This filter can perform additional processing of the result, such as modifying the HTTP response. The OutputCacheAttribute class is one example of a result filter.
Exception filter, which executes if there is an unhandled exception thrown somewhere in action method, starting with the authorization filters and ending with the execution of the result. Exception filters can be used for tasks such as logging or displaying an error page. The HandleErrorAttribute class is one example of an exception filter.
Q. What is the order of execution if multiple Action Filters implemented?
A. 1. Authorization filter
2. Action filter
3. Result filter
4. Exception filter
Q. what are asp.net MVC view engines?
A. Web Forms view engine (ASPX),
Razor, or
an open-source view engine such as Spark, NHaml, or NDjango
Q. what are model binders asp.net MVC?
A. What Model binder does is that it takes the values coming from an HTML page and map it to a corresponding model. This is a very useful since it relieves the developers from writing all the “type casting” and “HTML-Model mapping” code. The Model binder is capable of retrieving the data from HTML form variables, POSTed variables and files, query string parameters and the values added in the routes.
Q. what are model binders asp.net MVC?
A. The following list describes available ASP.NET MVC model binders and associated data types.
1) ByteArrayModelBinder(System.byte[]): Maps a browser request to a byte array.
2) LinqBinaryModelBinder(System.Data.Linq.Binary): Maps a browser request to a LINQ System.Data.Linq.Binary object.
3) FormCollectionModelBinder: Maps a browser request to a System.Web.Mvc.FormCollection. (It's internal)
4) HttpPostedFileBaseModelBinder(System.Web.HttpPostedFileBase): Binds a model to a posted file.
5) Default Model Binders The supported types for the DefaultModelBinder are Primitive types, such as String etc, Model classes, and generic collections List etc.
6) Data Annotation Model Binder to perform validation within an ASP.NET MVC application
6) Custom Model Binders, User can define custom model binder.
Q. What is the page lifecycle of an ASP.NET MVC?
A. Following process are performed by ASP.Net MVC page:
1) App initialization
2) Routing
3) Instantiate and execute controller
4) Locate and invoke controller action
5) Instantiate and render view
Q. what is data annotation?
A. Data Annotation Model Binder to perform validation within an ASP.NET MVC application
-When you use the Data Annotations Model Binder, you use validator attributes to perform validation. The System.ComponentModel.DataAnnotations namespace includes the following validator attributes:
Range – Enables you to validate whether the value of a property falls between a specified range of values.
ReqularExpression – Enables you to validate whether the value of a property matches a specified regular expression pattern.
Required – Enables you to mark a property as required.
StringLength – Enables you to specify a maximum length for a string property.
Validation – The base class for all validator attributes.
Q. What are IoC Containers?
A. [TBW]
Q. What is MVC Passive view Architecture?
A. This pattern is yet another variation on model-view-controller. As with these the UI is split between a view that handles display and a controller that responds to user gestures. The significant change with Passive View is that the view is made completely passive and is no longer responsible for updating itself from the model. As a result all of the view logic is in the controller. As a result, there is no dependency in either direction between the view and the model.
View - Views are Web forms, Event Driven. We should not write any business logic here. As followed MVC passive view pattern, view will not talk to Model
Controller -All the service calls will happen through controller. UI logics and validations are written here.
Model - It contains Entities, Repositories, and Services. All the business logics are written here.
Q. What is the significance of ASP.NET routing?
A. ASP.NET MVC uses ASP.NET routing, to map incoming browser requests to controller action methods.
ASP.NET Routing makes use of route table. Route table is created when your web application first starts.
The route table is present in the Global.asax file.
Q. What are the 3 segments of the default route, that is present in an ASP.NET MVC application?
A 1st Segment - Controller Name
2nd Segment - Action Method Name
3rd Segment - Parameter that is passed to the action method
Example: http://dotnetdeewane.com/Article/id/5
Controller Name = Article
Action Method Name = id
Parameter Id = 5
Q. What is the significance of NonActionAttribute?
A. In general, all public methods of a controller class are treated as action methods.
If you want prevent this default behaviour, just decorate the public method with NonActionAttribute.
Q. What are the advantages of ASP.NET MVC?
A. The main advantages of ASP.net MVC are...
Enables the full control over the rendered HTML.
Provides clean separation of concerns (SoC).
Enables Test Driven Development (TDD).
Easy integration with JavaScript frameworks.
Following the design of stateless nature of the web.
No ViewState and PostBack events.
Q. What is TempData in ASP.NET MVC?
A. TempData is meant to be a very short-lived instance, and you should only use it during the current and the subsequent requests only.
TempData is session, so they're not entirely different. However, the distinction is easy to understand, because TempData is for redirects, and redirects only. So when you set some message in TempData and then redirect, you are using TempData correctly.
Q. What is ViewData in ASP.NET MVC?
A. The controller can add key/values pairs to the ViewData. The data is then passed to the view when the view is rendered. The view can add to or change the data, which will be sent to the controller when the view is posted as part of a request.
For MVC we would like to maintain data when the hit comes to controller and reaches the view and finally the scope of the data should expire.
So, ViewData is the new session management technique has been introduced in ASP.NET MVC framework.
eg.
public ActionResult Index()
{
ViewData["CurrentDateTime"] = DateTime.Now.ToString();
return View();
}
Q. What is ViewBag in ASP.NET MVC?
A. MVC 2 controllers support a ViewData property that enables you to pass data to a view template using a late-bound dictionary API. In MVC 3, you can also use somewhat simpler syntax with the ViewBag property to accomplish the same purpose.
For example, instead of writing ViewData["Message"]="text",
you can write ViewBag.Message="text". You do not need to define any strongly-typed classes to use the ViewBag property
Q. What are the different return type controllers action method supports in ASP.NET MVC?
A. There 12 kinds of results in MVC, at the top is “ActionResult”class which is a base class
ViewResult - Renders a specified view to the response stream
PartialViewResult - Renders a specified partial view to the response stream
EmptyResult - An empty response is returned
RedirectResult - Performs an HTTP redirection to a specified URL
RedirectToRouteResult - Performs an HTTP redirection to a URL that is determined by the routing engine, based on given route data
JsonResult - Serializes a given ViewData object to JSON format
JavaScriptResult - Returns a piece of JavaScript code that can be executed on the client
ContentResult - Writes content to the response stream without requiring a view
FileContentResult - Returns a file to the client
FileStreamResult - Returns a file to the client, which is provided by a Stream
FilePathResult - Returns a file to the client
Q. What is Asynchronous Controller in ASP.NET MVC?
A. The asynchronous controller enables you to write asynchronous action methods. It allows you to perform long running operation(s) without making the running thread idle.
Asynchronous action methods are useful when an action must perform several independent long running operations.
Suppose we have three operations which takes 500, 600 and 700 milliseconds.
With the synchronous call, total response time would be slightly more than 1800 milliseconds.
However, if the calls are made asynchronously (in parallel), total response time would be slightly more than 700 milliseconds, because that is the duration of longest task/operation.
Q. What is “WebAPI” in MVC4?
A. “WebAPI” is the technology by which you can expose data over HTTP following REST principles.
WebAPI'" is built from scratch and the only goal is to create HTTP services using REST. Due to the one point focus for creating “REST” service “WebAPI” is more preferred.
Q. What is the difference between WebAPI and Controller in MVC4?
A. Use Controller to render your normal views.
ApiController action only return data that is serialized and sent to the client.
They work similarly in Web API, but controllers in Web API derive from the ApiController class instead of Controller class.
The first major difference you will notice is that actions on Web API controllers do not return views, they return data.
Q. What is the difference between “ActionResult” and “ViewResult”?
A. ActionResult” is an abstract class while “ViewResult” derives from “ActionResult” class. “ActionResult” has several derived classes like “ViewResult” ,”JsonResult” , “FileStreamResult” and so on.
“ActionResult” can be used to exploit polymorphism and dynamism. So if you are returning different types of view dynamically “ActionResult” is the best thing.
Q. What is the difference between tempdata ,viewdata and viewbag?
A. Temp data: -Helps to maintain data when you move from one controller to other controller or from one action to other action. In other words when you redirect,“tempdata” helps to maintain data between those redirects. It internally uses session variables.
View data: - Helps to maintain data when you move from controller to view.
View Bag: - It’s a dynamic wrapper around view data. When you use “Viewbag” type casting is not required. It uses the dynamic keyword internally.
A. MVC(Model View Controller) is an architectural pattern for building applications. ID separates the applications in 3 main component
Model, View and Controller. Model is nothing but the domain object or data, View is the component which contains user interface and Controller do the processing or incoming requests.
Q. What are the Disadvantages of MVC Pattern?
A. Even if this pattern comes with a lot of advantages, there are distinct disadvantages too. Firstly, it is too complex to implement and is not suitable for smaller application; rather, implementing this pattern in such applications will have adverse effects in the application's performance and design.
Q. What is an Action Filter in MVC?
A. In ASP.NET MVC, controllers define action methods that usually have a one-to-one relationship with possible user interactions, such as clicking a link or submitting a form. For example, when the user clicks a link, a request is routed to the designated controller, and the corresponding action method is called.
Sometimes you want to perform logic either before an action method is called or after an action method runs. To support this, ASP.NET MVC provides filters. Filters are custom classes that provide both a declarative and programmatic means to add pre-action and post-action behaviour to controller action methods.
Q. How many types of action filters are there in MVC?
A. ASP.NET MVC provides the following types of action filters:
Authorization filter, which makes security decisions about whether to execute an action method, such as performing authentication or validating properties of the request. The AuthorizeAttribute class is one example of an authorization filter.
Action filter, which wraps the action method execution. This filter can perform additional processing, such as providing extra data to the action method, inspecting the return value, or canceling execution of the action method.
Result filter, which wraps execution of the ActionResult object. This filter can perform additional processing of the result, such as modifying the HTTP response. The OutputCacheAttribute class is one example of a result filter.
Exception filter, which executes if there is an unhandled exception thrown somewhere in action method, starting with the authorization filters and ending with the execution of the result. Exception filters can be used for tasks such as logging or displaying an error page. The HandleErrorAttribute class is one example of an exception filter.
Q. What is the order of execution if multiple Action Filters implemented?
A. 1. Authorization filter
2. Action filter
3. Result filter
4. Exception filter
Q. what are asp.net MVC view engines?
A. Web Forms view engine (ASPX),
Razor, or
an open-source view engine such as Spark, NHaml, or NDjango
Q. what are model binders asp.net MVC?
A. What Model binder does is that it takes the values coming from an HTML page and map it to a corresponding model. This is a very useful since it relieves the developers from writing all the “type casting” and “HTML-Model mapping” code. The Model binder is capable of retrieving the data from HTML form variables, POSTed variables and files, query string parameters and the values added in the routes.
Q. what are model binders asp.net MVC?
A. The following list describes available ASP.NET MVC model binders and associated data types.
1) ByteArrayModelBinder(System.byte[]): Maps a browser request to a byte array.
2) LinqBinaryModelBinder(System.Data.Linq.Binary): Maps a browser request to a LINQ System.Data.Linq.Binary object.
3) FormCollectionModelBinder: Maps a browser request to a System.Web.Mvc.FormCollection. (It's internal)
4) HttpPostedFileBaseModelBinder(System.Web.HttpPostedFileBase): Binds a model to a posted file.
5) Default Model Binders The supported types for the DefaultModelBinder are Primitive types, such as String etc, Model classes, and generic collections List etc.
6) Data Annotation Model Binder to perform validation within an ASP.NET MVC application
6) Custom Model Binders, User can define custom model binder.
Q. What is the page lifecycle of an ASP.NET MVC?
A. Following process are performed by ASP.Net MVC page:
1) App initialization
2) Routing
3) Instantiate and execute controller
4) Locate and invoke controller action
5) Instantiate and render view
Q. what is data annotation?
A. Data Annotation Model Binder to perform validation within an ASP.NET MVC application
-When you use the Data Annotations Model Binder, you use validator attributes to perform validation. The System.ComponentModel.DataAnnotations namespace includes the following validator attributes:
Range – Enables you to validate whether the value of a property falls between a specified range of values.
ReqularExpression – Enables you to validate whether the value of a property matches a specified regular expression pattern.
Required – Enables you to mark a property as required.
StringLength – Enables you to specify a maximum length for a string property.
Validation – The base class for all validator attributes.
Q. What are IoC Containers?
A. [TBW]
Q. What is MVC Passive view Architecture?
A. This pattern is yet another variation on model-view-controller. As with these the UI is split between a view that handles display and a controller that responds to user gestures. The significant change with Passive View is that the view is made completely passive and is no longer responsible for updating itself from the model. As a result all of the view logic is in the controller. As a result, there is no dependency in either direction between the view and the model.
View - Views are Web forms, Event Driven. We should not write any business logic here. As followed MVC passive view pattern, view will not talk to Model
Controller -All the service calls will happen through controller. UI logics and validations are written here.
Model - It contains Entities, Repositories, and Services. All the business logics are written here.
Q. What is the significance of ASP.NET routing?
A. ASP.NET MVC uses ASP.NET routing, to map incoming browser requests to controller action methods.
ASP.NET Routing makes use of route table. Route table is created when your web application first starts.
The route table is present in the Global.asax file.
Q. What are the 3 segments of the default route, that is present in an ASP.NET MVC application?
A 1st Segment - Controller Name
2nd Segment - Action Method Name
3rd Segment - Parameter that is passed to the action method
Example: http://dotnetdeewane.com/Article/id/5
Controller Name = Article
Action Method Name = id
Parameter Id = 5
Q. What is the significance of NonActionAttribute?
A. In general, all public methods of a controller class are treated as action methods.
If you want prevent this default behaviour, just decorate the public method with NonActionAttribute.
Q. What are the advantages of ASP.NET MVC?
A. The main advantages of ASP.net MVC are...
Enables the full control over the rendered HTML.
Provides clean separation of concerns (SoC).
Enables Test Driven Development (TDD).
Easy integration with JavaScript frameworks.
Following the design of stateless nature of the web.
No ViewState and PostBack events.
Q. What is TempData in ASP.NET MVC?
A. TempData is meant to be a very short-lived instance, and you should only use it during the current and the subsequent requests only.
TempData is session, so they're not entirely different. However, the distinction is easy to understand, because TempData is for redirects, and redirects only. So when you set some message in TempData and then redirect, you are using TempData correctly.
Q. What is ViewData in ASP.NET MVC?
A. The controller can add key/values pairs to the ViewData. The data is then passed to the view when the view is rendered. The view can add to or change the data, which will be sent to the controller when the view is posted as part of a request.
For MVC we would like to maintain data when the hit comes to controller and reaches the view and finally the scope of the data should expire.
So, ViewData is the new session management technique has been introduced in ASP.NET MVC framework.
eg.
public ActionResult Index()
{
ViewData["CurrentDateTime"] = DateTime.Now.ToString();
return View();
}
Q. What is ViewBag in ASP.NET MVC?
A. MVC 2 controllers support a ViewData property that enables you to pass data to a view template using a late-bound dictionary API. In MVC 3, you can also use somewhat simpler syntax with the ViewBag property to accomplish the same purpose.
For example, instead of writing ViewData["Message"]="text",
you can write ViewBag.Message="text". You do not need to define any strongly-typed classes to use the ViewBag property
Q. What are the different return type controllers action method supports in ASP.NET MVC?
A. There 12 kinds of results in MVC, at the top is “ActionResult”class which is a base class
ViewResult - Renders a specified view to the response stream
PartialViewResult - Renders a specified partial view to the response stream
EmptyResult - An empty response is returned
RedirectResult - Performs an HTTP redirection to a specified URL
RedirectToRouteResult - Performs an HTTP redirection to a URL that is determined by the routing engine, based on given route data
JsonResult - Serializes a given ViewData object to JSON format
JavaScriptResult - Returns a piece of JavaScript code that can be executed on the client
ContentResult - Writes content to the response stream without requiring a view
FileContentResult - Returns a file to the client
FileStreamResult - Returns a file to the client, which is provided by a Stream
FilePathResult - Returns a file to the client
Q. What is Asynchronous Controller in ASP.NET MVC?
A. The asynchronous controller enables you to write asynchronous action methods. It allows you to perform long running operation(s) without making the running thread idle.
Asynchronous action methods are useful when an action must perform several independent long running operations.
Suppose we have three operations which takes 500, 600 and 700 milliseconds.
With the synchronous call, total response time would be slightly more than 1800 milliseconds.
However, if the calls are made asynchronously (in parallel), total response time would be slightly more than 700 milliseconds, because that is the duration of longest task/operation.
Q. What is “WebAPI” in MVC4?
A. “WebAPI” is the technology by which you can expose data over HTTP following REST principles.
WebAPI'" is built from scratch and the only goal is to create HTTP services using REST. Due to the one point focus for creating “REST” service “WebAPI” is more preferred.
Q. What is the difference between WebAPI and Controller in MVC4?
A. Use Controller to render your normal views.
ApiController action only return data that is serialized and sent to the client.
They work similarly in Web API, but controllers in Web API derive from the ApiController class instead of Controller class.
The first major difference you will notice is that actions on Web API controllers do not return views, they return data.
Q. What is the difference between “ActionResult” and “ViewResult”?
A. ActionResult” is an abstract class while “ViewResult” derives from “ActionResult” class. “ActionResult” has several derived classes like “ViewResult” ,”JsonResult” , “FileStreamResult” and so on.
“ActionResult” can be used to exploit polymorphism and dynamism. So if you are returning different types of view dynamically “ActionResult” is the best thing.
Q. What is the difference between tempdata ,viewdata and viewbag?
A. Temp data: -Helps to maintain data when you move from one controller to other controller or from one action to other action. In other words when you redirect,“tempdata” helps to maintain data between those redirects. It internally uses session variables.
View data: - Helps to maintain data when you move from controller to view.
View Bag: - It’s a dynamic wrapper around view data. When you use “Viewbag” type casting is not required. It uses the dynamic keyword internally.
Comments
Post a Comment