I’m running through a tutorial using ASP.NET MVC and Entity Framework. In the meantime though, I wanted to give a short explanation of what the MVC framework actually is.
- What is MVC?
- How MVC “Works”
- What Am I Working On Now?
What is MVC?
MVC is a web application framework which stands for “Model-View-Controller”. The big deal with MVC is a principle called “Separation of Concerns” – The Model, View and Controller each have one role, separate from the other roles. This helps organize the code, since you know which area of your project will hold which kind of code, and assist in testing.
How MVC “Works”
Models are classes that define a data set for the user to interact with, and provides data to the View to present to the user.. I am creating a small MVC web app to show a list of baseball teams and their rosters – I needed one model (class) to define a team, and a second model to define a player.
Controllers are classes which handle all of the programming logic, including processing HTTP requests.. When a user clicks a link on your web app, it’s not looking for a static file, like you might have on a typical webpage or app. Instead, it calls a method inside a Controller class, which prompts it to perform some kind of action. This might be logging you into the site, or deleting/adding/updating data in a database. Controllers
When a user clicks a link, instead of downloading a static web page, a method inside one of the Controllers is called. The code inside that method will perform some kind of action and, usually, return some kind of data. Working with data involves referencing one or more data models, which specify what kind of data to work with. The resulting data is then passed to the View and presented to the user.
What Am I Working On Now?
I’m working on one of the tutorials on Microsoft’s ASP.NET website, Getting Started with Entity Framework 6 Code First using MVC 5. This is the “Contoso University” tutorial.
I am following the tutorials and manually typing them into a project, but there will be two parts to this project: One is the verbatim code from the tutorial. However, I’m also creating a second part of the web app showcasing a list of Fictional Little League Baseball Teams and their rosters.
It will be simple – for now it’ll just be teams and rosters – but I wanted to take the principles shown in the tutorial and do something other than manually copying code. It’s too easy to get mindless copying stuff; making something else based on that code is a crutch, but it’s a good start towards doing it totally on my own.
It also makes for bland reading to blog about copying code verbatim.
My next post will show my notes as I get the first part of this tutorial working, up through initializing a database using Entity Framework Code First.