A MVC interview - Interviewer and Interviewee interaction

Sukeshmarla
Posted by in ASP.NET category on for Beginner level | Points: 250 | Views : 3000 red flag
Rating: 4.33 out of 5  
 6 vote(s)

In this article we have explained A MVC interview - how the interaction between Interviewer and Interviewee goes.

Interviewer: How many years of ASP.NET MVC experience you have?

Candidate: Its 2.5. Candidates please note if you are new to ASP.NET MVC then view video and learn from it.

Interviewer: Ok. Let’s start. Your CV says most of your earlier projects are in Web Forms and newer ones are in ASP.NET MVC. What made you migrate to ASP.NET MVC from Web Forms?

Candidate: In our current organization we had two issues.

  1. One we were unable to unit test our projects properly because of tightly coupling between code behind and UI.
  2. We had a plan to create a responsive UI and in Web Forms it was quite difficult to get control over HTML and so it’s difficult to design responsive UI.

Interviewer: How come ASP.NET MVC solves these issues?

Candidate:

  1. In Asp.net MVC Code behind is replaced with Controller which will handle the User interaction logic. Best part is unlike Web Forms Controller is not tightly coupled with UI. It made Unit Testing an easy task.
  2. Secondly in ASP.NET MVC we don’t have support for traditional server controls which force us to use HTML for UI design. Ultimately we will get complete control over our HTML and hence responsive UI design becomes possible.

Interviewer: Sound good. Answer this. What is the difference between MVC and ASP.NET?

Candidate:

  • MVC is an architectural pattern which describes how a project should structure? It defines what all components should be there is the system and how they interact.
  • Asp.net a technology in Microsoft stack which let us develop Web applications using any of the .net compliant language such as C# or VB.net.

Interviewer:Very nice. Would you like to add something more to the explanation?

Candidate: Asp.net has two flavors one which follows the code behind approach is called Web Forms where as another which is based on MVC architecture pattern is called Asp.Net MVC.

Interviewer: What are the different components of MVC architecture?

Candidate: They are as follows.

  1. Model – It has two parts. One is Business data and second one is Business Logic which works against business data.
  2. View – It makes UI part of our application.
  3. Controller – Handles the User interactions. In case of Web application there is nothing called as Event handling in reality. We have only requests and response. Whenever user sends a request that need to be handled by some kind of logic. Controller contain that logic in terms of action methods.

            a. It handle the user request.
            b. Talk to the Business logic in Model and get appropriate Business data if required.
            c. Choose the appropriate result for request which will be View result in more cases.
            d. It bind business data to View.
            e. Return View to the user.

Interviewer: Can you name some results you used an action method can return?

Candidate: Yes they are,

  • Content Result- which represents the scalar output.
  • RedirectToRouteResult – When browser receives it, it make a new request to application.
  • Empty Result – Represents null output. When browser receives it, it will do nothing and display a blank screen.
  • JsonResult – When client want to get data from server we use this result.

Interviewer: Did you used ViewData or ViewBag?

Candidate:

We can use viewdata or viewbag for transferring data from Controller to View. In our projects we didn’t used it because both of them does automatic boxing and convert our value to Object type. Thus while retrieving we need to explicitly unbox the value. It leads to performance issues.
Secondly with ViewBag/ViewData Intellisense won’t work and also compile time errors are least. In order to find out an error we have to rely on runtime exceptions.

Instead of ViewBag or ViewData we have used model to transfer data. We have made our View a strongly typed view and then transferred the data using Model.

Interviewer: But what was your take when view was expecting more than one kind of data. For an instance let say we want to display Logged in User’s information at the top of the page and at the same time in the middle portion you want to display Customer information. Is it possible to make a view a strongly typed view of two models?

Candidate:

We cannot make our View a strongly typed view of multiple models. In such scenarios we implemented View Models. Difference between Model and ViewModel is Model is Business data vs ViewModel is View specific data. In the above case I will create a MyViewModel class with two properties. One of type Customer and another of type User.

Code

public class MyViewModel
{
	public Customer MyCustomer{get;set;}
	public User MyUser{get;set;}
}

Interviewer: Any other scenario where you thought about implementing View Model in your project.

Candidate:

Yes. We used it to separate out Presentation logic and Data Transformation from the View.

Note: Click here to read more about View Model.

Thank you for reading.

Hope you enjoyed this conversation between an Interviewer and Candidate. We will be soon back with some more such topics. 

Page copy protected against web site content infringement by Copyscape

About the Author

Sukeshmarla
Full Name: Sukesh Marla
Member Level: Starter
Member Status: Member
Member Since: 8/7/2012 12:15:35 PM
Country: India
Corporate Training, Online Training, Video based training justcompile.com www.sukesh-marla.com
www.JustCompile.com
Learning is fun but teaching is awesome. Code re-usability is my passion ,Teaching and learning is my hobby, Becoming an successful entrepreneur is my goal. For technical trainings on various topics like WCF, MVC, Business Intelligence, Design Patterns, WPF and UML and many more feel free to contact SukeshMarla@Gmail.com or visit justcompile.com or visit www.sukesh-marla.com

Login to vote for this post.

Comments or Responses

Posted by: Chandradev819 on: 10/29/2014 | Points: 25
Nice article.

Login to post response

Comment using Facebook(Author doesn't get notification)