Friday, February 11, 2011

ASP.NET MVC – A Quick Introduction & Example

The ASP.NET MVC (model-view-controller) is an implementation of the popular MVC design pattern, but as the name implies, is ASP.NET-specific. The following example demonstrates the creation of a complete (albeit simple) Visual Studio project, database, and MVC code.


Step 1:  create the MVC project with Visual Studio.

Step 2:  create the SQL Server database.

Step 3:  create the controller.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using FootballStatsMvc.Models;  // add reference to our model
//
// GET: /FootballStats/
public ActionResult Index()
{
       var statsDB = new FootballStatsDataContext();
       var players = statsDB.Players;
      
       return
 View(players);
}

Step 4: create the model.

Step 5: create the view.

Step 6: add the new tab to the master page.

Source: FootballStatsMvc.zip

No comments:

Post a Comment