0

Two questions about MVC: 1) What is difference between .net MVC and Android MVC? 2) Why need to use ViewModels in MVC?

I would appreciate if anyone can answer these questions.

2 Answers2

0

reference from this

Model-View-Controller

In the MVC, the Controller is responsible for determining which View is displayed in response to any action including when the application loads. This differs from MVP where actions route through the View to the Presenter. In MVC, every action in the View correlates with a call to a Controller along with an action. In the web each action involves a call to a URL on the other side of which there is a Controller who responds. Once that Controller has completed its processing, it will return the correct View. The sequence continues in that manner throughout the life of the application:

Action in the View
    -> Call to Controller
    -> Controller Logic
    -> Controller returns the View.

One other big difference about MVC is that the View does not directly bind to the Model. The view simply renders, and is completely stateless. In implementations of MVC the View usually will not have any logic in the code behind. This is contrary to MVP where it is absolutely necessary as if the View does not delegate to the Presenter, it will never get called.

Community
  • 1
  • 1
Vaishali Sutariya
  • 5,093
  • 30
  • 32
0

MVC is a concept rather than a solid programming framework. You can implement your own MVC in any platforms.

Model: What to render

View: How to render

Controller: Events, user input

Question 1: Android MVC and .Net MVC

Android MVC:

In Android you don't have MVC, but you have the following:

  1. You define your user interface in various XML files by resolution, hardware, etc.
  2. You define your resources in various XML files by locale, etc.
  3. You extend clases like ListActivity, TabActivity and make use of the XML file by inflaters.
  4. You can create as many classes as you wish for your business logic.
  5. A lot of Utils have been already written for you - DatabaseUtils, Html.

More Ref : MVC pattern on Android

.net MVC :

ASP.Net MVC is an open source web application framework that implements the model–view–controller (MVC) pattern.

More Ref : http://en.wikipedia.org/wiki/ASP.NET_MVC_Framework

Question 2: Why need to use ViewModels in MVC?

ViewModel help us to organize and manage data in a strongly-typed view with more flexible way than complex objects like models or ViewBag/ViewData objects.It allow you to shape multiple entities from one or more data models or sources into a single object, optimized for consumption and rendering by the view.

  1. ViewModel contain fields that are represented in the view (for LabelFor,EditorFor,DisplayFor helpers)
  2. ViewModel can have specific validation rules using data annotations or IDataErrorInfo.
  3. ViewModel can have multiple entities or objects from different data models or data source.

More Ref: http://rachelappel.com/use-viewmodels-to-manage-data-amp-organize-code-in-asp.net-mvc-applications

Community
  • 1
  • 1
Kumar Manish
  • 3,746
  • 3
  • 37
  • 42