Sunday, 1 September 2013

30 - Asp.net Mvc Interview Questions

1. What is the full form of MVC?
Ans. Model-View-Controller

2. In which namespace MVC is defined?

Ans. System.Web.mvc

3. Define Model?

Ans. Model objects are the parts of the application that implement the logic for the application

4. Define View.

Ans. Views are the components that display the application s user interface (UI).

5. Define Controller.

Ans. Controllers are the components that handle user interaction, work with the model, and ultimately select a view to render that displays UI.

6. What is the area in asp.net MVC?

Ans. The area is a mini-MVC project within your principal project.

7. What is the layout in ASP.net MVC?

Ans. It is the same as a Master page in aspx pages but in Razor Language layouts are used instead of Master Page.

8. Explain the "page lifecycle" of ASP.NET MVC.

Ans.
  • App initialization
  • Routing
  • Instantiate and execute controller
  • Locate and invoke controller action
  • Instantiate and render view
9. Is it possible that one action method refers to more than one view?
Ans. Yes.


10. Define different return types of the controller action method.

Ans. 1. ViewResult
         2. JsonResult
         3. ActionResult
         4. PartialViewResult
         5. RedirectResult
         6. FileResult
         7. EmptyResult
         8. JavascriptResult
         9.ContentResult

11. What is the difference between TempData and ViewData?

Ans. TempData passes data from Controller to Controller while ViewData is used to pass data from Controller to View.

12. What is the difference between Html.Partial() and Html.RenderPartial()?

Ans. Html.Partial returns string value which can be stored in a variable. it is slower then Html.RenderPartial(). Html.RenderPartial returns void so they can not be stored in variables. It is faster.

13. Explain routing.

Ans. Routing helps to decide the URL structure and map the URL with the controller.
There are three parameters for routing
1. ControllerName
2. ActionMethodName
3. Parameter

14. How to implement Ajax in MVC?

Ans. Using two libraries
         1. Ajax libraries
         2. Jquery

15. How to send the result in json format in MVC?

Ans. Using JsonResult class.

16. What is the use of NonActionAttribute?

Ans. In MVC all public methods are treated as action methods, to prevent this we have to use NonActionAttribute.

17. Define the order of filters to be executed in MVC?

Ans. 1. Authorization filters
         2. Action filters
         3. Response filters
         4. Exception filters

18. Which filters are executed in the end?

Ans. "Exception filters"

19. What are the file extensions for Razor views?

Ans. 1. cshtml
         2. vbhtml

20. What is Bundle.config file?

Ans. Bundle.Config file is used to bundle javascript and css by using a bundling and minification system.

21. What is the use of HTML helpers in MVC?

Ans. HTML helpers are used to render HTML controls in the view

22. Which are the important namespaces used in MVC?

Ans.  System.Web.Mvc
          System.Web.Mvc.Ajax
          System.WEb.Mvc.Html
          System.WEb.Mvc.Async

23. What is the Database First Approach in MVC using Entity Framework?

Ans. Database first approach creates the model classes from the database which are used to link between controller and database.

24. What is Output Caching in MVC?

Ans. Output caching is used to cache the content returned by the controller and the content is not generated again when the controller is called again. So it mainly used to improve the performance of the MVC application.

25. What is a Partial View in MVC?

Ans. Partial View is just like user control in the web form application. It is reusable in multiple views so it reduces the code duplication.
HTML Helper renders partial view in 2 ways.
1. @Html.Partial("MyPartialView");
2. @Html.REnderPartial("MyPartialView");


26. How to maintain Session in MVC?
Ans. Using TempData, ViewData and ViewBag.

27. What are the file extensions for Razor view?

Ans. .cshtml : For C#
        .vbhtml : For Vb

28. What are the Actions in Asp.Net MVC?

Ans. Actions are methods in the Controller which are responsible for returning View.

29. What is ViewStart Page in Asp.net Mvc?

Ans. ViewStart page is the common page to use in multiple Views.

30. Which filter executed at the last?

Ans. Exception Filter

No comments:

Post a Comment

Thanks

SQL server tricky questions