To help illustrate some of the basics of how to handle form
input and posting scenarios with the ASP.NET MVC Framework, we are going to
build a simple product listing, product creation, and product editing
scenario. It will have three core end-user experiences:
Product Listing By Category
Users will be able to see a listing of all products within a
particular product category by navigating to the
/Products/Category/[CategoryID] URL:
Figure 1

Add New Product
Users will be able to add a new product to the
store by clicking the "Add New Product" link above. This takes
them to the /Products/New URL - where they will be prompted to enter details
about a new product to add:
Figure 2

When they hit save, the product will be added
to the database, and they will be redirected back to the product listing page.
Edit Product
On the product listing page users can click
the "Edit" link next to each product. This takes them to the
/Products/Edit/[ProductID] URL - where they can change the product details and
hit the Save button in order to update them in the database:
Figure 3

Our Data Model
We are going to use the SQL Server Northwind Sample Database
to store our data. We'll then use the LINQ to SQL object relational
mapper (ORM) built-into .NET 3.5 to model the Product, Category, and Supplier
objects that represent rows in our database tables.
We'll begin by right-clicking on our /Models sub-folder in
our ASP.NET MVC project, and select "Add New Item" -> "LINQ
to SQL Classes" to bring up the LINQ to SQL ORM designer and model our data objects:
Figure 4

We'll then create a partial
NorthwindDataContext class in our project and add some helper methods to
it. We are defining these helper methods for two reasons: 1) it avoids us
embedding our LINQ queries directly in our Controller classes, and 2) it will
enable us to more easily adapt our Controller to use dependency injection in
the future.
The NorthwindDataContext helper methods we'll
add look like below:
Figure 5

To learn more about LINQ and LINQ to SQL, please check out
my LINQ to SQL series here.