Model-View-Controller

MSDN Tutorials

Overview of ASP.NET Core MVC

Getting Started with ASP.NET Core MVC and Visual Studio

What Does MVC Look Like?

Flow of MVC

In Classic ASP, Web Forms, PHP, Cold Fusion (file-based systems), Web browser submits URL (URL maps to file location and name) to HTTP server as a request for a file. Http server locates files and the file does something.

In MVC, Web browser submits request to HTTP server which hands request off to a controller. Request comes into a method of a class. Controller is a class and you are calling its method.

Controller runs the logic. Controller retrieves Model and does stuff, e.g. process logon request, retrieve data for display.

Good coding practices dictate that your controller should hand-off calls to services, data access classes, etc.

Request --> Controller --> "Does Stuff"

A lot of time the "doing something" means retrieving data, Login request - controller requests list of users, get me a list of albums or artists; that result is the Model.

Model is packaged data to be presented to user. It only contains data. It is also a class.

  • Might be a View Model which is a class. Could be a collection, an array, a string, etc.
    • Model is not hooked up directly to a database. It is just a dataset for the user to interact with.
Model (shown as a suitcase) added to previous image.

View visually represents the Model. The View's job is to take the Model information and turn it into HTML. Note: No logic should be included in Views

 View (shown as a screen layout) added to previous image.

Separation of Concerns: each component acts autonomously of each other.

What's the Point?

Web Forms

Benefits of Using Web Forms

  View (shown as a screen layout) added to previous image.

Problem with Web Forms

  • Three different lifecycles (load SiteMaster, load Products, load Cart) to process prior to returning a single page to the user agent.
     View (shown as a screen layout) added to previous image.
  • Naming all the controls can be problematic.

Why MVC

  • MVC was designed to resolve problems related to Web Forms development.
  • MVC gives you the application structure from the start.
  • MVC helps developers to type better, cleaner code.
  • MVC apps have more classes and more methods, but less code in each.

Where To Go From Here

We have grouped the major concepts of MVC into tutorials which will give you a better overall understanding of each component, how it fits into the development workflow, and additional links which will provide scholars with an even deeper understanding of how to incorporate MVC into Web application project.

Links of Interest