Archive

Archive for the ‘LINQ’ Category

ASP.NET MVC – A Quick Introduction & Example

November 19, 2009 Leave a comment

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.

C# [FootballStatsController.cs]

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

Categories: ASP.NET MVC, C#, LINQ Tags: , ,
Follow

Get every new post delivered to your Inbox.