Summary:
We're required to have either Visual Studio 2008 or the free Visual Web Developer 2008 Express tools into order to delve into web development on the ASP.NET platform. Also needed is the ASP.NET MVC Framework to actually create ASP.NET MVC based web applications.
Following the URL in the book, microsoft.com/web/downloads/, takes you to this page:
Being one who likes having the bare essentials and knowing what's installed on my system I opted instead to head over to asp.net/mvc/ and download just the ASP.NET MVC Framework. Here I was greeted by several links including this one:
The link leads to another page containing several links:
The first leads back to the Web Platform Installer, which I was trying to avoid, and the second leads to a link for just the ASP.NET MVC Framework. The installer for the framework itself is only around 1.8 megabytes in size. Being on Windows 7 double clicking the installer brings up the usual "Are you sure you wanna do this?" dialog. After a few minutes the installer finishes by asking us if we want to view the README. Sure, why not?
Oh ok. Anyway, back to the book. We create a new project by going File->New Project, selecting the ASP.NET MVC Web Application project wizard and poking OK. We're asked if we want to create a test unit for the application and click OK again. The project structure is pictured in the book, as is the File->New Project steps, so to cut down on redudancy I'm going to avoid screen capturing things that are obvious. The book then talks about how the project is structured, what each directory contains, etc. So following that let's hit the Play button and see if the default project builds and runs:
Well that's something the book doesn't mention. What this dialog is basically telling us is that debugging isn't enabled since the Web.config file isn't properly set up for it. For now I'll leave it enabled since it'll be running this locally so there's no fear of other people poking around where they shouldn't. A few seconds later the web browser launches and we're taken to the default website which can be seen in the book. I click all of the links mentioned in the book and they all seem to work. One minor difference I found from the book is the port on which the local ASP.NET server runs on.
The next section covers the tests which I run and the results are identical to what is found in the book so there's not much to talk about there.
Now to add the NerdDinner database. Everything is exactly as it is in the book except:
As it turns out, I didn't install SQL Server Express 2005 when I installed Visual Studio 2008. One minor nitpick, why give me a link that I can't click? Alright, so going back to the Microsoft website I find SQL Server Express 2005 downloads and click the second link:
After the download finished (55 megabytes worth since I chose to go with the 64-bit version) and installed without incident I was ready to create the NerdDinner database. Again I added a database to the project this time without any pop up dialogs except the one specified in the book. Following the guide on creating the NerdDinner database tables was pretty straight forward. The creation of the LINQ to SQL models for the Dinners and RSVPs database tables is straight forward as well.
The creation of the DinnerRepository class and Dinner partial class was almost straight forward. The code in the book is missing the namespace statement which is required for the compiler to find the partial Dinner class. Since the LINQ to SQL models reside in the NerdDinner.Models namespace while all the copy and pasted classes where floating in the NerdDinner namespace. Fixing this is as simple as adding namespace NerdDinner.Models to any class found within the Models directory.
Next we add a new Controller, the DinnerController, which will be responsible for handling HTTP URL redirects. The idea behind the controller is that the parts of the URL specify what action withing the controller we're requesting. For example, in the new controller the pregenerated method Index() handles the URL localhost/Dinners/. The added method Details(int), used to display the details for a dinner, handles the URL localhost/Dinners/Details/
Observations
Somethings I've observed while using the ASP.NET MVC approach:
· Code-behinds are gone. Code, if any, is inline with the HTML.
· Instead of using controls in the "asp" namespace they're inlined as code sections, for example a hyperlink in ASP.NET MVC followed by a native ASP.NET hyperlink:
·
· <@sp:HyperLink NavigateUrl="http://www.microsoft.com" Text="Microsoft" />
· Normal loops (for, foreach) are used instead of the repeater control
· The MVC approach is similar to the MVVM approach used in WPF
No comments:
Post a Comment