Hi, this is my first tutorial of 2014 , and i want to start with one of my favorite topic : MVC & ASP.Net
Points of this tutorial :
- Fast (really very fast) Introduction to MVC
- Show me the code !!!
Ok.. Here we go !!
Fast (really very fast) Introduction to MVC
MVC = Model, View and Controller
The Model-View-Controller (MVC) architectural pattern separates an application into three main components: the model, the view, and the controller. The ASP.NET MVC framework provides an alternative to the ASP.NET Web Forms pattern for creating Web applications. The ASP.NET MVC framework is a lightweight, highly testable presentation framework that (as with Web Forms-based applications) is integrated with existing ASP.NET features, such as master pages and membership-based authentication. The MVC framework is defined in the System.Web.Mvc assembly.
The MVC framework includes the following components:
Models. Model objects are the parts of the application that implement the logic for the application's data domain. Often, model objects retrieve and store model state in a database. For example, a Product object might retrieve information from a database, operate on it, and then write updated information back to a Products table in a SQL Server database.
In small applications, the model is often a conceptual separation instead of a physical one. For example, if the application only reads a dataset and sends it to the view, the application does not have a physical model layer and associated classes. In that case, the dataset takes on the role of a model object.
Views. Views are the components that display the application's user interface (UI). Typically, this UI is created from the model data. An example would be an edit view of a Products table that displays text boxes, drop-down lists, and check boxes based on the current state of a Product object.
Controllers. Controllers are the components that handle user interaction, work with the model, and ultimately select a view to render that displays UI. In an MVC application, the view only displays information; the controller handles and responds to user input and interaction. For example, the controller handles query-string values, and passes these values to the model, which in turn might use these values to query the database.
All this translates to the following : Independence of different layers , parallel development , Easy implementation of Unit Test, and business complexity management.
Show me the code !! (Hello World ASP.Net MVC 3.0)
Ok, it´s time to Code and Coffee :)
For this tutorial we need :
Let´s start :
- Run Visual Web Developer 2010 Express
- Select File option from top menu, and then select New Project option
- "New Project" window appear
- Select from Installed Templates, "Visual C#" and then select "Web" option.
- From the right list , select "ASP.Net MVC 3 Web Application" template.
- Set project Name ("MvcHelloWorld" for this tutorial)
- Set project Location.
- Set Solution Name ("MvcHelloWorld" for this tutorial)
- Check "Create directory for this solution" option
- Click "OK" button.
- The New ASP.NET MVC 3 Project dialog box appear
- select Internet Application
- leave Razor as the default view engine.
- Click "OK" button.
- Default template for the ASP.NET MVC project has been created:
Maybe you think ... "That´s all ?" .. but not all end here :) , in next tutorial , we will learn how this application works and a little bit about ASP.NET MVC in the process
Thanks... And now you can close this browser and start to change some code :)