Matter to discuss is that if Model passing full information to a View, it's straight to use and simple to code too. Then what's matter with ViewModel? when it need to be used? As per industry experience, we have 2 scenarios where it needs to be implemented.
- View need to handle 2 Models and both models to be in side a single container
- View to handle indicators like, whether a user logged or not? Whether to render a portion or not which are logic belongs to View and we can't keep these under a Model
So you are very much in a position to explain to your client about why need to implement a View Model. Below I am explaining 2 different types of implementation of View Model. The 2nd one will use one more standard layer as Mapper.
1. ViewModel as a type to keep Entity Information and to pass it to the View -
public class MyController : Controller
{
public ActionResult Index()
{
OrderModel orderModel = <<Call to get Model>>
EnquiryModel enquiryModel = <<Call to get Model>>
DetailOrderViewModel viewModel= new DetailOrderViewModel
{
ShouldRenderLoginSection = !User.Identity.IsAuthenticated,
LoggedInName = User.Identity.Name ?? "",
OrderModel = orderModel,
EnquiryModel= enquiryModel
};
returnView(viewModel);
}
}
public classDetailOrderViewModel
{
public bool ShouldRenderLoginSection { get; set; }
public stringLoggedInName { get; set; }
public OrderModel OrderModel { get; set; }

Himanshu SinghalPosted Jun 13, 2012, 1:19 PM
hi ! After Reading your post i am get little Bit Confused that which approach is better one . Providing all entity in single Container or using the Mapper class.As i am developing the ERP in MVC using the Model class but Passing all the Model class to Controllers as a single entity . Can you Help me which approach will be Better one .