Asp.net mvc interview questions for beginners

Here are some common ASP.NET MVC job Interview Questions and Answers for beginners and professionals.

ASP.NET MVC Interview Questions Answers
Asp net MVC Job Interview Questions
  1. What is Model View Controller?
    • Model — It’s object definition ( a business entity), it is used to represent the application data.
    • View — It’s GUI, the presentation layer, is about how data is displayed on user interface.
    • Controller — Process the Request & Send the Response back, all business logic and data manipulation done here.
  2. Tell me the advantages of Asp.net MVC over ASP.NET?
    • Asp.net MVC Provides a clean separation of concerns among UI (Presentation layer), model (object defination/Entities) and Business Logic & data manipulation(Controller).
    • Easy to UNIT Test
    • Improved structuring of the code.
    • Improved reusability of model (object definition) and presentation layer functionalities (partial views)
    MVC pattern is all about on separating the content from presentation and data-processing from content
  3. How does 'page lifecycle' works in ASP.Net MVC works?
    • App initialize
    • Routing
    • Instantiate and execute controller
    • Locate and invoke controller actions
    • Instantiate and render partial view
    • Instantiate and render view
  4. What is Separation of Concerns in Asp.net MVC?
    It is the process of breaking the program into various distinct features which overlaps in functionality as little as possible. that's what MVC is designed for!
  5. What is Unobtrusive JavaScript? Explain with example.
    Unobtrusive JavaScript doesn't inter mix JavaScript code in your page html. Instead of using events like onclick and onsubmit, the unobtrusive JavaScript attaches to elements by their ID or class based on the HTML5 data- attributes
  6. What is Bundle.Config in ASP.Net MVC?
    "BundleConfig.cs" in ASP.Net MVC4 is used to register the bundles by the bundling and minification system. Many bundles are added by default including jQuery libraries like - jquery.validate, Modernizr, default CSS, additional CSS references etc.
  7. What are the difference between ViewBag and ViewData ?
    ViewBag is a wrapper around ViewData, which allows to create dynamic properties. Advantage of viewbag over viewdata will be : In ViewBag no need to typecast the objects as in ViewData. ViewBag will take advantage of dynamic keyword which is introduced in version 4.0. But before using ViewBag we have to keep in mind that ViewBag is slower than ViewData
  8. What is Layout in ASP.Net MVC?
    Layout pages are similar to master pages in traditional web forms. This is used to set the common look across multiple pages. if we don't specify a layout to any view, it takes the default one
  9. Explain RenderBody and RenderPage in ASP.Net MVC
    RenderBody is like ContentPlaceHolder in web forms. This will exist in layout page and it will render the child pages/views. Layout page will have only one RenderBody() method. RenderPage also exists in Layout page and multiple RenderPage() can be there in Layout page.
    more about Layouts, RenderBody, RenderSection and RenderPage
  10. What are Validation Annotations?

    Data annotations are attributes under the "System.ComponentModel.DataAnnotations" namespace. These attributes will be used for server-side validation and client-side validation is also supported. Four attributes -

    • Required
    • String Length
    • Regular Expression
    • Range

    Above attributes are used to cover the common validation scenarios.

  11. What is Area in ASP.Net MVC?
    Area is used to store the details of the modules of our project. This is really helpful for big applications, where controllers, views and models are all in main controller, view and model folders and it is very difficult to manage.

    This is how you can register

    protected void Application_Start()  
            {
                AreaRegistration.RegisterAllAreas();
            }
    
  12. Explain Dependency Injection in ASP.Net MVC?
    Dependency Injection is a design pattern and is used for developing loosely couple code. This is greatly used in the software projects. This will reduce the coding in case of changes on project design so this is vastly used.
  13. How to invoke child actions in ASP.Net MVC?

    We have "ChildActionOnly" attribute, need to use over action methods to indicate that action method is a child action.

    Here is a simple example of child action :
    [ChildActionOnly]             
    public ActionResult LeftNavigation()                 
    {
    //Logic here             
    return PartialView();                
    }
    
  14. How to handle exception at controller level in ASP.Net MVC?

    Exception Handling is simple in ASP.Net MVC and it can be done by just overriding "OnException", and set the result property of the filtercontext object to the view detail.

    Here is how
    protected overrides void OnException(ExceptionContext filterContext)                 
    { 
    }
    
    take a look more about Exception handling in asp.net mvc
  15. What “beforFilter()”,“beforeRender” and “afterFilter” functions do in Controller?
    • beforeFilter(): This function is run before every action in the controller. It's the right place to check for an active session or inspect user permissions.
    • beforeRender(): This function is called after controller action logic, but before the view is rendered, not used much, but may be required If you are calling render() manually before the end of a given action
    • afterFilter(): This function is called after every controller action, and after rendering is done. It is the last controller method to run
  16. What are AJAX Helpers in ASP.Net MVC?

    AJAX Helpers are used to create AJAX enabled elements ( like as Ajax enabled forms and links which performs the request asynchronously) and these are extension methods of AJAXHelper class which exists in namespace

    System.Web.ASP.Net MVC.
  17. What is Non Action method in ASP.Net MVC?

    In ASP.Net MVC all public methods have been treated as Actions. So if you are creating a method that you do not want to use, that can created as an action method then the method has to be with "NonAction" attribute as displayed below

    [System.Web.Mvc.NonAction]
    public void MyTestMethod()
    {
    //  logic here
    }
    
  18. What is the "HelperPage.IsAjax" Property?
    HelperPage.IsAjax property indicates whether Ajax is being used during the request of the Web page.
  19. What are the components required to create a route in ASP.Net MVC?
    • Name - This is the name of the route.
    • URL Pattern : Placeholders will be given to match the request URL pattern.
    • Defaults :When loading the application which controller, action to be loaded along with the parameter.
  20. What is PartialView in ASP.Net MVC?

    PartialView is similar to UserControls in traditional web forms. For re-usability purpose partial views are used.

    Partial Views can be rendered in following ways :

    Html.Partial()
    Html.RenderPartial()

    Learn more about partial view in asp.net mvc

  21. What is Caching in ASP.Net MVC?

    Caching is a technique that stores frequently used data. There are three type of caching in Asp.net

    • Output Caching
    • Data Caching
    • Fragment Caching

    take a look more about caching in asp.net mvc

  22. Difference between Authentication & Authorization ?
    Checking entry point credibility is called Authentication, done while login, and checking permission on some action is called Authorization
ASP.NET Course Online
Asp.net Course Online
ASP.NET MVC Tutorial
Interview Question Answers | Fresher Job Interview Tips