Difference between asp.net MVC and MVP? are they both same? - asp.net-mvc

I wanted to know the difference between asp.NET MVC and MVP, are they both same?
below is the architecture diagram I referred.
(Image URL:http://msdn.microsoft.com/en-us/library/ff647859.aspx)
the major difference I got to know between MVC and MVP from the diagram is, in MVC the Model updates the view and in MVP the Presenter updates the view.
But here is my confusion.Below is a asp.net MVC code sample.
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
return View();
}
}
here the Controller returns/updates the view so now according to the diagram it is MVP
Is asp.net mvc and MVP similar? if not what is the difference ?Can someone guide me.

Actually MVP is a subset of MVC pattern.
In your example of asp.net mvc the controller does not updates the view rather it just pass the model to the view and the view get updated according to the model.
But in MVP (which is usually used with winforms and webforms in Microsoft stack) the presenter get data from view, updates the model and when the model changed, the presenter will read the model and updates the view.

That MVC diagram looks misleading to me. I would regard this as a more actuate architectural diagram:
this is from a PHP site but here you can clearly see the relationship between the view and the controller.
The differences between MVC and MVP are subltle, this question (as mentioned above) clarifies those differences.
That MSDN page also clearly says
This content is outdated and is no longer being maintained. It is
provided as a courtesy for individuals who are still using these
technologies....
I think this resource pre-dates Asp.Net MVC.
The articles themselves are for something call the Composite UI Application Block and are from 2005. I'd go to http://www.asp.net/mvc/ for some more up to date and acurate information on MVC.

No.They are not the same. They are two different paradigms (design patterns) used for user interaction. Based on these paradigms, ASP.NET team developed two different frameworks for writing web applications. The first is ASP.NET Web Forms based on an event based form programming. The second is ASP.NET MVC which is based on using Model Views and Controllers (MVC).
I suppose you could start reading here which is written by one of the ASP.NET development team members.
Regarding the specific question. I think that the Controller updates the View using the Model to do it. Model does not do anything. Or this is the way I understand it, anyway...
Hope I helped!

Try to understand MVC and MVP concept without connection to any technology.
Action method in ASP.NET MVC controller returns ActionResult with View method doesn't break any pattern. It just say that controller functionality is done and let's render the view from markup with Razor/ASP.NET syntaŃ….
In ASP.NET world - ASP.NET MVC is impelemntation of MVC pattern. Forgotten Web Client Software factory is MVP implementation

Related

Is Microsoft's MVC implementation different from classic MVC pattern [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
In various articles on the web about ASP.NET MVC I've people mention that Microsoft's implementation of MVC is somehow different form the 'classic' MVC pattern.
But I've never seen anyone go into any detail on this, and at first glance I don't see how ASP.NET MVC is any different from what is described, say, here.
So my question is: does ASP.NET MVC really violate any MVC pattern principles?
The problem is really that MVC is a loosely defined pattern. The "M" could be interpreted as "everything in the business domain, from entities to business logic".
I wouldn't say that ASP.NET violate MVC, but rather interprets it loosely.
Some official MVC examples uses entity framework directly in the controllers which in my opinion is incorrect. Because then it doesn't act as a bridge between the model and the view. Instead it takes care of business logic (even if it's very basic logic) AND map the model info to the view.
ASP.NET MVC has something called view models which are not the M in MVC. They are instead used as an adapter between the model (or rather one of more entities in the Model) and the view, thus taking over a part of the responsibility that the controller has.
Generally yes, Microsofts implementation of the MVC pattern follows the main tenant of the MVC pattern. It has a Model, Controller and View that are responsible for slightly different aspects of the UI (remember MVC is a presentation pattern in this instance so it's only responsible for the UI (mostly))
Where Microsoft start to deviate is the introduction of some of the less clean (as in not 100% MVC) features, specifically
ViewBag
C# in the view (not razor as such but #helper
functions)
TempData
ViewData
Layouts
ViewModels
Some of the above are more contentious than others. Ultimately all these things are designed to speed up development, but move away from the idea that the controller builds a model that the view then renders (full stop).
Microsoft also has a tendency to explain MVC as a business logic pattern (as mentioned above it's a UI pattern).
So in the Microsoft world you often see example where the controller gets a model from (for example) Entity Framework does some business logic (business logic shouldn't really be in the controller) then passes it into a ViewModel (not really 100% MVC) and the view then renders it (manipulating the data using helper functions).
So they try and sell MVC as a one pattern fits all solution when it's not.
Although, I agree with other answers [in some respect], let me put it into a different perspective.
ASP.NET MVC is not a pattern but rather a framework in which you can write your software using MVC pattern, or rather its specific web-application version.
You shouldn't worry about Microsoft's implementation. Their implementation of MVC Framework has little to do with MVC pattern. To implement it, MS use many different patterns, I am sure. The key here, is to understand that MVC framework is not MVC. It allows you to develop using MVC pattern. And in this case, this pattern includes certain rules that you need to follow, like in other patterns - name controllers with Controller at the end, for example. But this is MS's implementation for you. So, you have View, Model and Controller. MVC Framework tells you, follow the rules and we will connect all these for you.
Now, if you go to MVC pattern as original pattern, all it tells you - separate view from controller and model. And separate model from controller. Because this way, you can reuse model and controller with different view, for example. Now, how you implement it - it is up to you. As long as it has characteristics I described above, this is MVC. So, again, MS gave you MVC framework, in which you have separate M-V-C. Therefore, when you write your M,V and C, you have separation which is original pattern describes. MVC framework takes care of the wiring for you.

Learning ASP MVC by example. Bonus: an example that uses MVVM in microsoft's MVC framework

I feel it is time to graduate from webforms to mvc. I've been programming webforms, and jquery for a long time.
Can you all suggest your favorite resources to learn this technology?
Bonus: I'm particularly interested in using a ViewModel (not necessarilly a MVVM framework) to pass my information around. Are there any good resources out there?
Thanks for all your help!
If you don't mind books I recommend Steven Sanderson's MVC book(s), the latest being "Pro ASP.NET MVC 3 Framework". It contains a very lengthy introducion and many good tips. After the intro it continues being very thorough and complete about MVC's features and extension points.
http://www.apress.com/9781430234043
You may want to wait for the MVC 4 edition though (each MVC version had a book so far).
Careful with ViewModels. In MVVM context it is a model with 'controller' methods. You'd do this client side.
A ViewModel in a MVC context can also be a domain model projection tailored to a view. Instead of passing a full domain model object to a view one would map a subset of it or perhaps expand some bits of it's detail data to a ViewModel that is an exact fit for what the view would present. Similarly you could have an EditModel that contains additional data for instance to supply the view with a list of selectable/possible values.
There are countless good ASP.NET MVC tutorials on the web. The best place to start is with the samples provided by Microsoft on the MVC site: http://www.asp.net/mvc/samples
For MVVM, you can look at a JavaScript library called Knockout.js which handles the view models on the client side.
As you progress, you can start exploring single page apps (SPAs) with MVC which combines some of the more advanced features of ASP.NET MVC with frameworks such as Knockout to produce a fully functioning app all on one page. A good example of that is the BigShelf Sample SPA from Microsoft.
It doesn't get any clearer than this example by Microsoft:
Intro to ASP.NET MVC 3 (C#) to start with ASP.NET MVC and
Views and ViewModels to start with View Models
By the same token there are numerous samples, examples and tutorial on the web, but the one I've mentioned is your next step to begin with, gives you an essence what what is this ASP.NET MVC about...
Hope this is of help to you & good luck with ASP MVC

Using same Model for MVVM and MVC

I have a query regarding MVVM and MVC. I am developing an Desktop Client and Web application. I intend to use WPF (and MVVM) to develop desktop client and ASP.Net MVC for web app.
I have never used ASP.Net MVC before although I have never truly liked Web Forms (except some features like Master Page, output Cache etc.) and I mostly use AJAX (jQuery), and handlers to populate HTML and processing inputs (I think I was close to MVC after reading about the pattern but in a different way).
Now these applications will mostly have same inputs, reports, and database. I am planning to create Model that can be re-used in MVVM and MVC both. But after reading various articles on these pattern, and analysis of ASP.Net MVC Code, I doubt that it could be done. In MVVM, View never knows Model while in MVC, Controller shares Model with View. Also, in ASP.Net MVC, a View (ASPX file) is derived from System.Web.Mvc.ViewPage and the labels/captions are populated from Model itself.
Is there a way I can use same Model for both applications?
Thank you.
Ritesh
In MVVM, View never knows Model while in MVC, Controller shares Model with View.
Not quite right. In MVVM the view is bound to a view model. Exactly the same as in ASP.NET MVC. In ASP.NET MVC a Controller doesn't share a Model with the View. It shares a View Model. It talks to the Model and then builds a View Model that is passed to the View.
Contrary to MVC in MVVM the View could talk to the Model but this happens indirectly throughout the View Model, so neither the View nor the Model know about each other's existence.
So you could perfectly fine have the same Models in both your Desktop client application and in your web application. The only difference will be the view models.

ASP.NET MVC Views and WebForm Pages inheriting from the same Page

I'm working on ASP.NET project that is written using WebForms. We are in a process of switching to MVC so we writing all new pages in MVC. There are some big parts of application that we don't want to rewrite just yet, like authentication which is located in our BasePage. BasePage is inherited from every WebForm page.
Question: Can an MVC View inherit from this common BasePage that is also used by WebForms? If Views can, would the BasePage run through it's normal page life cycle?
The short answer is not really.
Although MVC pages look and smell like webforms, they're different beasts. They use a new class called viewpage which inherits from page for starters.
Also in the MVC way of doing things, the view is too late to be doing things like security.
It would be better to spend time first converting your shared resources into service classes that you can re-use between webforms and MVC.
Simon

Can we say ASP.NET is also MVC ?

ASP.NET also has UI, Event Handling and if good logic layer is implemented then the BLogic layer too. So that can we say its Model View Control style. Or its not that ?
No. ASP.NET Web Forms is an implementation of Page Controller pattern.
Chapter of Fowler's PoEAA about the Page Controller on Google Books
As a pattern MVC is more concerned with the idea that the controller orachastrates the view and the model.
In Web Forms there is no controller. The View and the code behind (closest thing to a controller) are inherently the same thing, there is no separation of concerns.
Also depending on how you go about it, the model part of the MVC isn't necessarily your business logic. For us its literally a View Model, and contains data relevant to the specific view only. Business logic is handled in autonomous components.
With traditional web forms, I generally see the code behind (which is really part of the UI) having intimate knowledge of either business logic or data base access (and often a mixture of both).
Due to code behind it is hard to get away from this.
In my mind web forms create tightly coupled UI and business logic, and don't provide an easy way to enforce separation of concerns.
I'd say web forms does not adhere to the MVC pattern.
In MVC, all requests are routed to a Controller.
In ASP.NET all requests are routed to a Page. That is a View and not Controller.
ASP.NET better matches with MVP rather than MVC. Reason being, in MVP, a View is supposed to process user inputs/requests and pass it on to appropriate Presenters.

Resources