.Net Interview Questions and Answers

Search:

QuestPond's interview questions and answers on ViewModel in ASP.NET MVC(Model View Controller)

By : Shiv Prasad Koirala | Aug 22nd, 2014 | Views : 4652 | Comments : 0 Bookmark and Share

How to pass two models in one view in ASP.NET MVC(Model View Controller)?


This is one of the most confusing ASP.NET MVC(Model View Controller) interview questions among every beginner learning ASP.NET MVC(Model View Controller).


Normally in MVC(Model View Controller) one view is bound one Model.



In real time projects we always end up into a solution where we want more than one kind of model in a view. Let's understand how to tackle this solution.


Try to answer following questions one after other and then let see if you can understand it or no.


  1. Question: Let say you have been asked to create a simple C# method which accept customer name as argument, what you will do?

    Answer: I will simply create a method with parameter of type string.

  2. Question: Correct, Let say function is going to accept more than one kind of customer attributes. Example Customer_Name, Address etc. What will be your take on it?

    Answer: I will customer class and encapsulate all the attributes inside it and finally use Customer Type as the argument of method

  3. Question: Now let's come to ASP.NET MVC(Model View Controller). We want to create view which is going display Customer data in the screen. It will display Customer Address, Customer name etc. So how can I achieve it?

    Answer: I will create a Model called Customer encapsulating all the customer attributes and then create a strongly typed view out of it.

  4. Question: Now answer this. You have a view where you want to display both customer and department information. What you will do?

    Answer:  I got it I will create a third class which encapsulated both Customer class and Department class. Finally from that third class I will create a strongly typed view.


Example:



This kind of class is called as ViewModel in MVC(Model View Controller).


For technical trainings on various topics like WCF (Windows Communication Foundation), MVC (Model View Controller), Business Intelligence, Design Patterns, WPF, TFS and Basic fundamentals feel free to contact SukeshMarla@Gmail.com or visit www.sukesh-marla.com


For more stuff like this, click here. Subscribe to article updates or follow at twitter @SukeshMarla

 
Rate this Article :
1 Star
2 Stars
3 Stars
4 Stars
5 Stars
1 1 1 2 1
 
 
 
 

.NET interview questions 6th edition (Sixth edition) - By Shivprasad Koirala

In this article we will explain .NET interview questions 6th edition (Sixth edition) - By Shivprasad Koirala.... Read More

What is the difference between Stored Procedures and Function (SQL Server interview question with answers)?

In this article we will explain what is the difference between Stored Procedures and Function.For more articles and videos visit us on www.questpond.com... Read More

Explain MVC application life cycle?

In this article we will explain MVC application life cycle.For more articles and videos visit us on www.questpond.com... Read More

C# Design pattern interview questions with answers: - How Singleton is different from Static class?

In this article we will explain How Singleton is different from Static class.... Read More

WCF interview questions and answers: - What is the difference between Service endpoint and Client endpoint?

In this article we will explain What is the difference between Service endpoint and Client endpoint.... Read More

.NET interview questions 6th edition (Sixth edition) - By Shivprasad Koirala

In this article we will explain .NET interview questions 6th edition (Sixth edition) - By Shivprasad Koirala.... Read More

What is the difference between Stored Procedures and Function (SQL Server interview question with answers)?

In this article we will explain what is the difference between Stored Procedures and Function.For more articles and videos visit us on www.questpond.com... Read More

Explain MVC application life cycle?

In this article we will explain MVC application life cycle.For more articles and videos visit us on www.questpond.com... Read More

C# Design pattern interview questions with answers: - How Singleton is different from Static class?

In this article we will explain How Singleton is different from Static class.... Read More

WCF interview questions and answers: - What is the difference between Service endpoint and Client endpoint?

In this article we will explain What is the difference between Service endpoint and Client endpoint.... Read More

Article Categories

Learn in Hindi