
254Microsoft Visual Studio 2010: A Beginner’s Guide
The skeleton code produced by VS gives you some working examples that you can build on and move forward. One item that VS doesn’t produce is the Model, which is discussed next.
Creating the Models
As stated previously, the Model represents the data for the application. The example in this section uses LINQ to SQL to produce the Model for this application. To create the Model, add a LINQ to SQL entity Model by
In more sophisticated scenarios, you would have additional objects that held business logic or other data that isn’t associated with LINQ to SQL. This book keeps tasks at a basic level so that you can understand how to use VS. You can put Model objects in the Models folder or a separate class library. This chapter uses the Models folder.
Building Controllers
Requests come directly to a Controller, which we discussed earlier. As shown in Figure
Listing 9-1 The HomeController class
C#:
using System;
using System.Collections.Generic; using System.Linq;
using System.Web; using System.Web.Mvc;
namespace MyShopCS.Controllers
{
[HandleError]
public class HomeController : Controller
{
public ActionResult Index()
{
ViewData["Message"] = "Welcome to ASP.NET MVC!";