First time here? Check out the site's "greatest hits" or read a post from the archives. Feel free to leave a comment or ask a question, and consider subscribing to the latest posts via RSS or e-mail. Thanks for visiting!
Do you Tweet? Follow me on Twitter @shanselman or learn how to use Twitter!
« Hanselminutes Podcast 103 - Quetzal Brad... | Main | The Weekly Source Code 19 - LINQ and Mor... »

image A number of folks wanted the code from my talk at Mix, specifically the "complete application" example with CRUD (Create, Read, Update, Delete) so here it is.

It's nothing pretty to look at, but it makes a number of points with ASP.NET MVC:

  • It uses the Default Routes to do everything.
  • It uses a ViewUserControl to avoid duplication in a Form.
  • It includes the PagedList<T> that makes Linq to SQL easier in grids.
  • It's insanely simple. There's like nothing there and it works well.
  • It uses lambdas to generate URLs like:
    • Html.ActionLink<ProductController>(c => c.Edit(p.ProductID),"Edit")
    • Which says "if someone were to call Edit with ProductID as a parameter, what would the URL look like?" The system will then use the lambda along with the already declared routes and figure out the best URL. This is very DRY and lets us change our URLs in one place and have those changes reflected everywhere.

If you want to run it you need:

I known it's cheesy to do demos with Northwind, and we're actively working on more real world, more interesting samples. That said, I'd much rather show off your code, so if you do something cool and Open Source with MVC, let me know. BTW, I've added an ASP.NET MVC category to this blog.

UPDATE #1: PhilHa updated Brad Abrams older (and much more comprehensive) Northwind code to ASP.NET MVC Preview 2, so you can download that much better code below as well.

UPDATE #2: Looks like ASP.NET MVC Preview 2 runs pretty well on Mono. Anyone want to get Northwind up over there as well?

Technorati Tags: ,,


Tuesday, March 11, 2008 11:05:18 PM (Pacific Standard Time, UTC-08:00)
I happen to like the Northwind database. Its simplicity means that we are not distracted from what you are really trying to demonstrate. Everyone understands what categories and products are, so there is no time wasted learning the domain. I have seen demonstrations with 'real-world' databases and not learned a thing.

Thanks for publishing this example!
Tuesday, March 11, 2008 11:32:16 PM (Pacific Standard Time, UTC-08:00)
Great.. thank you Scott
Wednesday, March 12, 2008 4:50:39 PM (Pacific Standard Time, UTC-08:00)
Nice, that mini MVC flowchart looks tasty. You don't happen to have a link to that picture alone?
Wednesday, March 12, 2008 5:31:59 PM (Pacific Standard Time, UTC-08:00)
Johan - That's just from the slides from my talk. You can download those.
Wednesday, March 12, 2008 8:12:17 PM (Pacific Standard Time, UTC-08:00)
Thanks, for the samples..

Thursday, March 13, 2008 9:49:12 AM (Pacific Standard Time, UTC-08:00)
Excellent. I don't wonder why Microsoft hire you. ^^
Thursday, March 13, 2008 11:30:06 AM (Pacific Standard Time, UTC-08:00)
Scott:

I'm wondering if I missed some bit of information. I downloaded the MVC preview 2, but it behaves strangely on my XP machine w/ VS2008 vs my Vista PC with VS2008.

On the XP machine, if I create a project, I get prompted for the project name, but not for any solution info, etc. I then get prompted to create a test project and I am greeted with what appears to be a normal VS project screen. When I run the project for the first time (before making any changes), I get the dialog to modify the Web.config for debugging, which seems very normal. The app runs and I get the page I expect to see. However, after I save the project and try to run the app again (still with no changes), I am prompted to add a NEW web.config file because debugging is not enabled. This is weird! If I say OK, I am propmted to replace the file. If I say yes, I get a message that says "The operation could not be completed. Not implemented" If I choose to run without debugging, I get a page that says "Directory Listing -- /" and that's it.

I have a Vista virtual machine running under MS Virtual PC 2007 (on the same XP machine), and on that VM I have VS2008 with MVC Preview 2. I don't get any of the aforementioned errors on the VM. Is there an issue with XP? When I first select the MVC Web app template on the Vista VM, I am prompted for the project name, solution, etc., something that doesn't happen on the XP machine.

Any thoughts would be most appreciated.

Tortilla
Tortilla Curtain
Thursday, March 13, 2008 12:12:19 PM (Pacific Standard Time, UTC-08:00)
Are you using it in IIS6? You might need to add .MVC to your routes as IIS6 doens't (easily) support extensionless URLs.
Thursday, March 13, 2008 12:34:09 PM (Pacific Standard Time, UTC-08:00)
Sorry, I left out the web server info. No, I'm not using IIS, I'm using the ASP.NET Development Server. I'm literally running this as staight up as you can. It may well be something with my PC, but I figured I'd fish around to see if you or anyone else had heard of this type of behavior. I'm testing it out on my Vista VM and enjoying it very much. I'll try it on my home XP computer tonight and see what happens...

Tortilla
Tortilla Curtain
Thursday, March 13, 2008 5:00:28 PM (Pacific Standard Time, UTC-08:00)
Scott:

I tried this on my home PC, and received the exact same behavior. The only differences in setup were that my home PC has IE 7.0 and VS 2008 Pro, whereas my work PC (the one I wrote about previously) had VS 2008 Team and IE 6.0. Any other ideas?
Tortilla Curtain
Friday, March 14, 2008 7:27:19 AM (Pacific Standard Time, UTC-08:00)
One more bit of info for you. I created a brand new XP SP2 VM and put VS 2008 Team on it. Then I put ASP.NET MVC Preview 2 on first, with no other ASP.NET MVC or 3.5 previews of any type. In this case, it worked just fine. I think something is going on with an XP machine that has a prevoious version of the ASP.NET 3.5 extensions preview, on which you instaall ASP.NET MVC Preview 2. The difference is visible right away, because on the VM I described above, when you create an ASP.NET MVC Web Application, you get three lines in the new project dialog (Name, Location and Solution Name). On the two other XP machines, I only got one line, Name, and the project wasn't saved right away. This wasn't an issue on the Vista VM, even though I had the previous 3.5 extensions loaded.
Tortilla Curtain
Friday, March 14, 2008 4:55:18 PM (Pacific Standard Time, UTC-08:00)
Hi Scott

I'm really quite taken with the MVC approach. One question, since you're looking at data access here, are there any plans to support an aysnchronous model within MVC.

Piers
Piers
Friday, March 14, 2008 7:09:14 PM (Pacific Standard Time, UTC-08:00)
Thanks for the sample!! Where are the unit tests?
Sunday, March 16, 2008 8:57:51 AM (Pacific Standard Time, UTC-08:00)
Scott,

I really enjoyed the 4 screencasts on MVC, good stuff.

I have your sample from the demo and can't seem to run it and wondered if there was some configuration I might have missed. When I attempt to run with CTRL-F5, using the ASP.NET development server, I get just a directory listing when IE loads up and the app does not run at all.

I am on XP and can create my own MVC Preview 2 projects and they run just fine. I assume if I can run my own MVC 2 apps then yours should run as well. I opened your sample with both File-->Open->Project/Solution and tried File->Open->Web Site, both ran the same way.

Thoughts?

Thanks.
Sunday, March 16, 2008 8:58:19 AM (Pacific Standard Time, UTC-08:00)
Scott,

I really enjoyed the 4 screencasts on MVC, good stuff.

I have your sample from the demo and can't seem to run it and wondered if there was some configuration I might have missed. When I attempt to run with CTRL-F5, using the ASP.NET development server, I get just a directory listing when IE loads up and the app does not run at all.

I am on XP and can create my own MVC Preview 2 projects and they run just fine. I assume if I can run my own MVC 2 apps then yours should run as well. I opened your sample with both File-->Open->Project/Solution and tried File->Open->Web Site, both ran the same way.

Thoughts?

Thanks.
Sunday, March 16, 2008 1:10:05 PM (Pacific Standard Time, UTC-08:00)
Hi, Scott.

As I told you a few days ago, I have adapted the "Less Cheesy Northwind sample" for Visual Web Developer Express.

It can be downloaded from my blog. Although it is in Spanish, you'll see the link to the project's zip file at the bottom of the post.

Thank you very much.
Jose.

Tuesday, March 18, 2008 5:37:02 PM (Pacific Standard Time, UTC-08:00)
Why does the web.config have an http handler to restrict all .aspx files? This is not present in the default MVC template that you would create from New Project. Is there any reason you put this in?

<add verb="*" path="*.aspx" type="System.Web.HttpNotFoundHandler" validate="true"/>

Thanks,
-Jeff
Wednesday, March 19, 2008 2:35:11 AM (Pacific Standard Time, UTC-08:00)
Hi,
Scott,
I had a look at your examples and videos on asp.net site.
I have a question on deployment. In the real world we are going to deploy an application to a web server, app server and database server. Can you explain how this will work for a MVC application?
I presume the controller will need to be on the web server as routing will need to call to the appropriate controller based on the url. Is it here that we seperate what gets deployed to a server? i.e view and controllers are on the web server and model is on the app server
Thanks Noel
noel
Sunday, April 13, 2008 2:15:53 AM (Pacific Standard Time, UTC-08:00)
Hi Scott,
I love the sample videos & code, great work!

However i've been getting an error with the paged list results for page '0':

This:
http://localhost:52265/Product?page=0

Generates the error:
"The null value cannot be assigned to a member with type System.Int16 which is a non-nullable value type."
The error is pointing to this line in the PagedList method:

this.AddRange(source.Skip(index * pageSize).Take(pageSize).ToList());

Do you have any pointers as to why its not accepting a 0 value?

Many thanks

Ben
Ben
Comments are closed.

Contact

Sponsors

Hosting By

Hot Topics

Tags

Calendar

<July 2009>
SunMonTueWedThuFriSat
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

Archives

July, 2009 (4)
June, 2009 (26)
May, 2009 (16)
April, 2009 (13)
March, 2009 (17)
February, 2009 (17)
January, 2009 (18)
December, 2008 (32)
November, 2008 (17)
October, 2008 (22)
September, 2008 (16)
August, 2008 (14)
July, 2008 (25)
June, 2008 (19)
May, 2008 (17)
April, 2008 (17)
March, 2008 (26)
February, 2008 (21)
January, 2008 (28)
December, 2007 (19)
November, 2007 (17)
October, 2007 (31)
September, 2007 (39)
August, 2007 (37)
July, 2007 (43)
June, 2007 (37)
May, 2007 (32)
April, 2007 (38)
March, 2007 (29)
February, 2007 (46)
January, 2007 (31)
December, 2006 (27)
November, 2006 (31)
October, 2006 (32)
September, 2006 (39)
August, 2006 (34)
July, 2006 (40)
June, 2006 (18)
May, 2006 (31)
April, 2006 (34)
March, 2006 (30)
February, 2006 (38)
January, 2006 (44)
December, 2005 (19)
November, 2005 (34)
October, 2005 (24)
September, 2005 (37)
August, 2005 (20)
July, 2005 (24)
June, 2005 (33)
May, 2005 (16)
April, 2005 (22)
March, 2005 (34)
February, 2005 (15)
January, 2005 (37)
December, 2004 (28)
November, 2004 (30)
October, 2004 (34)
September, 2004 (22)
August, 2004 (34)
July, 2004 (18)
June, 2004 (64)
May, 2004 (49)
April, 2004 (21)
March, 2004 (29)
February, 2004 (29)
January, 2004 (36)
December, 2003 (25)
November, 2003 (24)
October, 2003 (59)
September, 2003 (42)
August, 2003 (24)
July, 2003 (44)
June, 2003 (29)
May, 2003 (21)
April, 2003 (30)
March, 2003 (27)
February, 2003 (47)
January, 2003 (50)
December, 2002 (31)
November, 2002 (38)
October, 2002 (44)
September, 2002 (15)
May, 2002 (2)
April, 2002 (4)

Google Ads