MVC Interview Questions Part-1 - International Days

International Days

Internationally important Days


Home Top Ad

Post Top Ad

Monday, 3 August 2015

MVC Interview Questions Part-1

Hi all here I am again, every programmers always looking for optimum MVC interview questions. Now i am trying gather all MVC Interview questions and answers and share it with you guys. Please pardon me if I miss something  if anything popup your mind then add down as comments

Q.What is MVC routing?

A. URL Routing is the routing done by MVC which is , When we type something in the url , then it will first invoke the RouteConfig.RegisterRoutes(RouteTable.Routes); which is in Global.asax.cs Application_Start() method , then it will call the

     public static void RegisterRoutes(RouteCollection  
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home",
                                action = "Index", 
                                id = UrlParameter.Optional}

Which is in App_start=>RouteConfig class you can find out the RegisterRoutes method here . Here we can define the structure of our url and here it will decide which controller and action should be invoked. This process is url Routing

Q.What is URL rewriting?

A.URL rewriting is entire diff concept Let us assume our controller name is Customer and action name is Login when we run the application our url will be like the below http://Localhost:233/Customer/Loginbut the client needed http://Localhost:233/Login only, for SEO purposes In order to achieve this we have to rewrite the url by keeping the same controller and action name to know more about url rewriting i have explained attribute rewriting in

Q. What is MVC (Model-View-Controller)

A. MVC is an architectural pattern which separates the representation and user interaction. It’s divided into three broader sections, Model, View, and Controller. Below is how each one of them handles the task.
  • The View is responsible for the look and feel.
  • Model represents the real world object and provides data to the View.
The Controller is responsible for taking the end user request and loading the appropriate Model and View.

Q.MVC Life cycle

A. Any web based application has mainly two steps one is analyzing the request and second one is creating response according to the request, MVC also do the same thing
Creating the request:-
Fill route :- MVC requests are mapped into route table, The actual url contains the controller name and action name ,the first thing creating the request is filling the route table with route which is happen in the global.asax
Fetch route:-Depending on the url, search the route table to create RouteData which has information of controller and action name which has to be invoke
Request context created:-Routedata object id used to create requestcontext object
Controller instance create :-RequestObject is send to MvcHandler for creating instance, once controller class object is created it calls the "Execute" of controller class
Creating response object:-Executing the action and sending the response as result to the view .

Q.Difference between ASP.NET MVC and ASP.NET WebForms

ASP.NET Web Forms uses Page controller pattern approach for rendering layout, whereas ASP.NET MVC uses Front controller approach. In case of Page controller approach, every page has its own controller, i.e., code-behind file that processes the request. On the other hand, in ASP.NET MVC, a common controller for all pages processes the requests.

Q.What is the difference between viewdata,Viewbag and tempdata

As http is a stateless protocol , we are not able to maintain the state , That is why they implemented different techniques Session,etc. But in MVC, Microsoft introduced different objects to maintain state.
Viewdata:-Used to communicate between controller and corresponding view
Life time ,exists only when the view loads.
ViewBag:-Nothing but a collection of viewdata, ViewData is a dictionary object while ViewBag is a dynamic property we can accessible using string key and requires typecasting Life time, exists only when the view loads.
TempData:-We can pass data from one action to another it can maintain data between redirects Life time is tempdata become null when it is used once.

Q.Is it possible to unit test an MVC application without running the controllers in an ASP.NET process?

Yes, all the features in an MVC application are interface based and hence mocking is much easier. So, we don't have to run the controllers in an ASP.NET process for unit testing.

Q.Name a few different return types of a controller action method?

1. ViewResult
2. JavaScriptResult
3. RedirectResult
4. ContentResult
5. JsonResult

Q.What is the significance of NonActionAttribute?

This attribute indicates that the controller method is not an action method
By default all of the public method which is defined in the controller , is considered as an action method , If you want to define an public method which is not an action method then use the Non-action attribute

Q.What are the different types of filters, in an mvc application?

Sometimes you want to perform a logic to be run even before the action method invokes , for that purpose , ASP.NET mvc provides filters. Filters are custom classes which provide both declarative and programmatic means to add preaction post action behavior to controller action methods.
Type of filters

Now taking this discussion further, Let us first discuss the various types of filters that can be implemented to inject custom processing logic.

Authorization filter
Action filter
Result filter
Exception filter

Q. What is the meaning of Unobtrusive JavaScript?

This is a general term that conveys a general philosophy, similar to the term REST (Representational State Transfer). Unobtrusive JavaScript doesn't intermix JavaScript code in your page markup.

Eg : 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.

Q.MVC 4 New features

MVC 4 features having two category MVC Framework and mvc project template

MVC 4 Framework
  • Add controller to the other folders
  • Task support for asynchronous controllers
  • Bundling and magnification
  • Enabling Logins from Facebook and other websites using OAuthconfig
  • App_Start folder separated classes
  • Display modes using this we could select the different browsers
  • Azure SDK
  • Database migration
MVC Project template
  • Mobile Project template
  • Empty Project template
  • Enhanced default project template
Q.What are the new features in Asp.Net MVC5 ?
  • Introducing One ASP.NET
  • Introducing Asp.Net One Identity
  • Introducing Bootstrap in the MVC template
  • Introducing Filter overrides (Overriding filters)
  • Introducing Authentication Filters
  • Introducing Web API 2
  • Introducing OAuth 2.0 Authorization in MVC 5
  • OData Improvements in MVC 5(Full support for $select, $expand, $batch, and $value)
  • Introducing ASP.NET SignalR 2.0
  • Attribute routing
Q.What’s Bootstrap is new MVC 5 ?

MVC project template is updated in MVC 5 to use Bootstrap for better look and feel. Now you can easily customize. For more information
Bootstrap In Short:
With the updated MVC template, You can do Customization very easily
Better look and feel.

Q.Sub-domain Routing

We can map our ASP.NET MVC areas to sub-domains by using the Sub-domain property of the RouteAreaAttribute. Doing so ensures that the routes for the area are matched only when requests are made to the specified sub-domain. Here’s how:

[RouteArea(“Users”, Subdomain = “users”)]
public class SubdomainController : Controller
public ActionResult Index() { /* … */ }

Q.Is OAuth 2.0 support’s for Web API and Single Page Application ?

The MVC Web API and Single Page Application project templates now support authorization using OAuth 2.0. OAuth 2.0 is a authorization framework for authorizing client access to protected resources. It works for a variety of clients like for different browsers & mobile devices.

Q.What are the OData Improvements ?

Full Support for $select, $expand, $batch & $value
Much improved extensibility
Type less support (No need to define CLR types)

Ref :-

Q.How to use Cookie in MVC.

HttpCookie cook = new HttpCookie("Transfer");
cook.Expires = DateTime.Now.AddSeconds(1);
cook.Value = "from transfer cookies";

Q.What is ViewSatrt.cshtml

Starting from mvc 3 we could add a file called Viewstart.cshtml.
View start file can be used as to define common Layout page , we could pragmatically change the layout page according to our needs.It will execute when each view is loading View start also loads so no need of giving any layout in each view
This enable a lot of flexibility.And avoid repeating common code in view start file

Q.What is the difference between each version of MVC 2, 3 , 4, 5 and 6?

  • ASP.NET MVC and Web API has been merged in to one.
  • Dependency injection is inbuilt and part of MVC.
  • Side by side - deploy the runtime and framework with your application
  • Everything packaged with NuGet, Including the .NET runtime itself.
  • New JSON based project structure.
  • No need to recompile for every change. Just hit save and refresh the browser.
  • Compilation done with the new Roslyn real-time compiler.
  • vNext is Open Source via the .NET Foundation and is taking public contributions.
  • vNext (and Rosyln) also runs on Mono, on both Mac and Linux today.

  • One ASP.NET
  • Attribute based routing
  • Asp.Net Identity
  • Bootstrap in the MVC template
  • Authentication Filters
  • Filter overrides
  • MVC 4
  • Refreshed and modernized default project templates
  • New mobile project template
  • Many new features to support mobile apps
  • Enhanced support for asynchronous methods
  • Razor
  • Readymade project templates
  • HTML 5 enabled templates
  • Support for Multiple View Engines
  • JavaScript and Ajax
  • Model Validation Improvements
  • Client-Side Validation
  • Templated Helpers
  • Areas
  • Asynchronous Controllers
  • Html.ValidationSummary Helper Method
  • DefaultValueAttribute in Action-Method Parameters
  • Binding Binary Data with Model Binders
  • DataAnnotations Attributes
  • Model-Validator Providers
  • New RequireHttpsAttribute Action Filter
  • Templated Helpers
  • Display Model-Level Errors

Q.What is html helpers

Html helpers will help us to create different html controls in the view

Q.What is data annotation validation in MVC

In we could do the validation using data annotation which is so simple and very easy to implement .we can decorate the viewmodel properties with Dataannotation class which we need validation .
The common annotation present are

  • Required – Indicates that the property is a required field
  • DisplayName – Defines the text we want used on form fields and validation messages
  • StringLength – Defines a maximum length for a string field
  • Range – Gives a maximum and minimum value for a numeric field
  • Bind – Lists fields to exclude or include when binding parameter or form values to model properties
  • ScaffoldColumn – Allows hiding fields from editor forms
Please refer a simple example how to use the annotation in viewmodel

public class RegistrationViewModel
[Display(Name = "User name")]
public string UserName { get; set; }

[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
[Display(Name = "Password")]
public string Password { get; set; }

[Display(Name = "Confirm password")]
[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
public string ConfirmPassword { get; set; }


Q.What is dependency injuction

In Object oriented programming, the objects works together in a collaboration model where these are contributes and consumers . These process create dependency between object and components on time being theses dependencies are difficult to manage . These scattered dependency will grow un-manageable
The dependency injunction is a particular type of implementation of inversion of control means objects cannot create another objects an outside component will create the objects mainly injecting through the constructor. This is called dependency injunction.
Advantage :
  • Reduces class coupling
  • Increases code reusing
  • Improves code maintainability
  • Improves application testing
Q.What is Dependency Resolution

MVC 3 introduced a new concept called a dependency resolver, which greatly simplified the use of dependency injection in your applications. This made it easier to decouple application components, making them more configurable and easier to test.
Support was added for the following scenarios:

Controllers (registering and injecting controller factories, injecting controllers)
Views (registering and injecting view engines, injecting dependencies into view pages)
Action fi lters (locating and injecting filters)
Model binders (registering and injecting)
Model validation providers (registering and injecting)
Model metadata providers (registering and injecting)
Value providers (registering and injecting)

Q.What is AuthConfig.cs in MVC4

AuthConfig.cs is used to configure security settings, including sites for OAuth login.

Q. What is BundleConfig.cs in MVC4

BundleConfig.cs in MVC4 is used to register bundles used by the bundling and minification
system. Several bundles are added by default, including jQuery, jQueryUI, jQuery validation, Modernizr, and default CSS references.

Q. What is FilterConfig.cs in MVC4

This is used to register global MVC filters. The only filter registered by default is the HandleErrorAttribute, but this is a great place to put other filter registrations.

Q. What is RouteConfig.cs in MVC4

RouteConfig.cs holds the granddaddy of the MVC config statements, Route configuration.

Q.What is WebApiConfig.cs in MVC4

Used to register Web API routes, as well as set any additional Web API configuration settings.


  1. Replies
    1. Hope it helped you, Thanks for the comment

    2. Machine Learning Projects for Final Year machine learning projects for final year

      Deep Learning Projects assist final year students with improving your applied Deep Learning skills rapidly while allowing you to investigate an intriguing point. Furthermore, you can include Deep Learning projects for final year into your portfolio, making it simpler to get a vocation, discover cool profession openings, and Deep Learning Projects for Final Year even arrange a more significant compensation.

      Python Training in Chennai Project Centers in Chennai

  2. Replies
    1. Thanks for the comment , glad to know that it helped you. Please comment if you have any doubt i will try to help you as i could .

  3. Tks very much for your post.

    Avoid surprises — interviews need preparation. Some questions come up time and time again — usually about you, your experience and the job itself. We've gathered together the most common questions so you can get your preparation off to a flying start.

    You also find all interview questions at link at the end of this post.

    Source: Download Ebook: Ultimate Guide To Job Interview Questions Answers:

    Best rgs

  4. Replies
    1. Hope it helped you, Thanks for your feedback .

  5. I truly like you're composing style, incredible data, thankyou for posting. website management


Post Bottom Ad