Rebuilding imar.spaanjaars.com in ASP.NET MVC 2 - Part 5 - RTW

You may have noticed that I released the final MVC 2 version of my web site at imar.spaanjaars.com a few days ago.

The biggest change you'll notice is the clean URL structure as discussed here in part 3 of this series. But besides cleaner URLs, a lot has changed under the hood, making it easier for me to manage the site, its content and users, view logs and make change to the UI (which I plan to do somehwere in the futute). Compared to the older ASP.NET 3.5 Web Forms version of the site, I have been able to decrease the LOC (Lines of Code) by 50 percent. Now, LOCs don't say a whole lot about maintenance complexity, but still, it's an interesting achievement.

Instead of disceting the whole site and showing you how I built each feature, I'll be posting a number of links to books, articles, blog posts and forums that have helped me building this web site. 'll be updating this post when I find other interesting stuff, or recall what sources I used to fix certain problems I ran into while building my ASP.NET MVC 2 web site.

Getting Started

As discussed here, you probably want to get yourself a copy of the book Pro ASP.NET MVC Framework by Steven Sanderson. There's an ASP.NET MVC 2 version coming out by the end of this month. Additionally, you may want to check out Professional ASP.NET MVC 1.0 or the upcoming 2.0 version of that book, both published by Wrox.

Another great place to start is the MVC section of the official ASP.NET web site. In particular, the following areas are very useful:

Blogs you shouldn't miss

Dealing with Exceptions and Request Validation

jQuery

Unit Testing

Routing

Miscellaneous Stuff

Generating Slugs (the SEO friendly versions of categories and titles of posts)

Data Binding and Data Access

Best Practices

Castle Stuff


Where to Next?

Wonder where to go next? You can read existing comments below or you can post a comment yourself on this article .


Consider making a donation
Please consider making a donation using PayPal. Your donation helps me to pay the bills so I can keep running Imar.Spaanjaars.Com, providing fresh content as often as possible.



Feedback by Other Visitors of Imar.Spaanjaars.Com

On Friday, May 28, 2010 2:01:03 PM John said:
I just want to ask you, are you using ViewModel to build your site. If you using it how did you accomplish with your Repository pattern?
On Friday, May 28, 2010 2:03:37 PM Imar Spaanjaars said:
Hi John,

Yes, for most views I use a ViewModel. I then copy data from the ViewModel into my own model using either UpdateModel or custom mapping code.

Take a look here for some more ideas on View Models: http://blogs.msdn.com/b/simonince/archive/2010/01/26/view-models-in-asp-net-mvc.aspx

Cheers,

Imar
On Friday, May 28, 2010 3:22:47 PM John said:
Wow, thank you for the quick response. I read the article and it's very informative. I just wonder which variant did you use?
On Friday, May 28, 2010 3:39:39 PM Imar Spaanjaars said:
Hi John,

All three, depending on what I needed and how complex things got.

Imar
On Saturday, May 29, 2010 6:06:14 AM Premnath said:
Hi Imar I am a surgeon who recently got intrested in building an Electronic medical Record. I just went book after book video after video, they all explain bits and pieces and I got lost in the middle, it was very frustrating till I came across your book Begining ASP.net4. It was so easy to follow than the rest for a new person. Thanks for that book.

My question is should I start learning ASP.net mvc as I hear so much about it and you your self is upgrading your website to it, I am wondering is this the right way for a beginner like me?

Thanks for your advice and suggestion?
On Saturday, May 29, 2010 7:41:48 AM Imar Spaanjaars said:
Hi Premnath,

Good to hear you like my book so much and that it helped you a lot!

With regard to MVC: it's not replacing Web Forms; it's positioned next to it as an alternative. Each technology has its own advantages and disadvantages. My advice: read more about the differences and then determine what fits your scenario best: http://www.google.com/#hl=en&source=hp&q=mvc+versus+webforms

I mainly rebuilt my site as an exercise; to see what you run into when converting from one to the other. Had my site already been in MVC, I probably would have done the reverse.

Cheers,

Imar
On Tuesday, June 01, 2010 4:07:37 PM Kurt Schroeder said:
Thanks you again for this and the other articles you have given us. I decided to try the Code Only found in CTP. The example i tried was a very simple one, but it worked easily enough and gave me what i always prefer: A project that cannot be over written by the designer. I was curious if you had a chance to give it a look over and if so what you thought of it.

Thanks
KES
On Tuesday, June 01, 2010 7:11:57 PM Imar Spaanjaars said:
Not sure what project you are referring to, so I cannot give you my opinion. How about providing a bit more detail?

Imar
On Tuesday, June 01, 2010 8:01:23 PM Kurt Schroeder said:
Of course and appologies,
Here are the links to the preview and walk through, http://www.microsoft.com/downloads/en/confirmation.aspx?familyId=af18e652-9ea7-478b-8b41-8424b94e3f58&displayLang=en
http://blogs.msdn.com/b/adonet/archive/2009/06/22/feature-ctp-walkthrough-code-only-for-the-entity-framework.aspx
I am far from an authority on Entity or NHibernate, but i do have an opinion. If you are starting a project without an existing database I consider it a great opportunity to take advantage of model first design. The example given in the walk through takes you through to creating the database from your model, but does not really do too much else. For me that is enough. A friend of mine is on the fluent-Nhibernate project and he introduced me to a reduced xml implementation of NHibernate using fluent. The Code Only CTP reminds me of fluent in that you are staying more in code. I realize this can present its own set of issues, and I have yet to see any issues, but this certainly does not mean they do not exist.
There is one small problem. The PostConfiguration constructor needs to have these two lines included:
       Relationship(p => p.Author).CascadeOnDelete = false;
       Relationship(p => p.Poster).CascadeOnDelete = false;
Otherwise you will get an error when you attempt to build your database from the model.
On Tuesday, June 01, 2010 8:20:14 PM Imar Spaanjaars said:
Ah, POCO, now I see. Out of CTP, fortunately.

VS 2010 ships with (on-line available) T4 templates that help yoo with this and make it a lot easier to have your classes and contexts generated for you.

My opinion: it's great stuff. Both Model First and Poco are new in EF 4 and really help to create persistence ignorant code solutions. I've been using these concepts in a number of projects and really like it.
My advise: get Julie Lerman's second edition of Programming Entity Framework.

Cheers,

Imar
On Tuesday, June 01, 2010 9:45:08 PM Steve S. said:
Hi Imar,

Although Sanderson and I have the same initials and first name, I'm not him. I have, however, read his book, highly recommend it and have built my two sites (ComputerScribe.com & KulaKiko.com) from what I learned in it; and am looking forward to ordering his MVC2 book in a few weeks when it's released.

What I'd like to know about the new MVC'd Imar.Spaanjaars.com site is what you used for data access (EF4, Linq2Sql, or ...)? Did you use DI/IOC? If so which one? (Castle Windsor, Ninject, ...) As one geek to another, just curious what you did under the hood, so to speak?
On Tuesday, June 01, 2010 9:48:52 PM Steve S. said:
I just saw your part 2 for the site rebuild where you mostly answered my questions, EF and Castle Windsor. Did you use EF1 or EF4?

Steve
On Wednesday, June 02, 2010 7:09:13 AM Imar Spaanjaars said:
Hi Steve,

I used EF 4. Wanted to do this with as many new techniques as possible so started with the rebuild when VS 2010, EF 4 and MVC 2 were all still in beta.

Cheers,

Imar
On Wednesday, June 02, 2010 12:44:22 PM Kurt Schroeder said:
"..My opinion: it's great stuff. Both Model First and Poco are new in EF 4 and really help to create persistence ignorant code solutions. I've been using these concepts in a number of projects and really like it.
My advise: get Julie Lerman's second edition of Programming Entity Framework..."

It is an enjoyable surprise when two people i know independently speak positively of each other. I am going through Julie’s rough cut on SafariBooksOnline.com. The same book you recommended above. When I suggested she take a look at your article series it became obvious she was well aware of work and spoke positively of your abilities. T4 templates seem to be a feature Microsoft denies knowledge of. I liken it to covert black ops. Most developers I know have heard of it, but believe it an unsubstantiated rumor. Microsoft does not claim knowledge of its existence. Truthfully, I mean they seem to be actively not pushing it. Please pardon the dry humor.
On Wednesday, June 02, 2010 1:09:52 PM Premnath said:
Will you be writing a book on beginning MVC. It will be nice for beginners. Hope you would. Please write it in the same style as the Beginning ASP.net4.
On Wednesday, June 02, 2010 1:12:29 PM Imar Spaanjaars said:
Hi Kurt,

Good stuff indeed. I agree it's an enjoyable surprise.

I also agree T4 is Microsoft's Best Kept Secret in Visual Studio. However, it looks like they are actively trying to promote it, but it's not picked up that well by the masses. Take a look here for example: http://tinyurl.com/4efgt7

Lots of background and links to other T4 sites, tools and articles. Also, the EF framework uses it a lot under the hood and the team has made T4 templates available for customization purposes.

Just minutes ago I was using a T4 template in .Less (DotLess). I keep getting amazed about what T4 can do for you... ;-)

Cheers,

Imar
On Wednesday, June 02, 2010 1:13:27 PM Imar Spaanjaars said:
Hi Premnath,

I don't have any plans for an ASP.NET MVC book yet, but who knows.... It's definitely an interesting subject....

Imar
On Monday, June 28, 2010 2:58:38 PM Kurt Schroeder said:
A quick what are you using questing...
I've decided to do a few smaller projects with Entity 4.0 to test the waters. I still like the idea of using attributes for validation on POCO's. Let's just say I'm still an old command line type who has to see everything or it will not feel comfortable. Using POCO's with Entity gives me this comfort level, at least for now and it leaves it open for using attribute validation. I've not considered if this is practical especially where  MVC is involved. I'm curious what your thoughts are at this point in the Great Entity Adventure? What would you recomend and if you are using attributes how are you putting them in place?

As always i appreciate your articles and comments.
Thanks
KES
On Monday, June 28, 2010 6:08:43 PM Imar Spaanjaars said:
Hi Kurt,

Yes, I think attributes still have a place in EF POCO classes. I haven't played around with this enough yet, but it should be feasible. I am thinking about this a lot as well, for a .NET 4 version of the article series, to be published somewhere in the future.

But attributes and validation are now an integral part of MVC using model validation. Haven't determined yet if it's enough and if there is still room for my attribute solution.

Would welcome any findings or feedback.

Cheers,

Imar
On Monday, June 28, 2010 11:58:14 PM Kurt Schroeder said:
You hit on my main concern and touched on the "side" issue. The Main concern is, is it enough and can it be expanded. The side issue is the conservative of my online person “Yankee Imperialist Dog” Cold War rhetoric aside I tend to the conservative when I have something that works. With a little home brew code generation and a small time investment in a library for the attributes life is not-half-bad at the moment. I like both entity (since 4.0) and MVC2. I liked NH but I always got trapped into the “lowest common version” when it came to the other open source frameworks out there. All were developed by some talented people whose efforts I appreciate, but the framework with the oldest version of the others where it is used becomes the winner. I’ve found myself sometimes working a year out of date with the newer versions. In the case of the attribute libraries this is really not an issue. As the saying goes, “If it ain’t broke, don’t fix it”.

As always your help and comments are appreciated!
KES
On Wednesday, November 17, 2010 5:30:39 AM Dennis said:
Oh. I can't connect your mvc site. I just want to see your mvc site. What's the problem? Please check out.
On Wednesday, November 17, 2010 7:42:10 AM Imar Spaanjaars said:
Hi Dennis,

Quote from this article:

>> You may have noticed that I released the final MVC 2 version of my web site at imar.spaanjaars.com a few days ago.

In other words, you are looking at the MVC version now; the other site was just a temporary work-in-progress.

Cheers,

Imar
On Wednesday, November 17, 2010 4:55:09 PM Kurt Schroeder said:
I'm very interested and have been in this series. All of my new develop is MVC and Entity. I'm still looking for the magic practical solution to all of the topics you are covering. In the end, like i did last time with n-Layer (http://imar.spaanjaars.com/476/n-layered-web-applications-with-aspnet-35-part-1-general-introduction) i may just use yours.

I would be remiss if i did not mention to you a book written by a local friend of mine. I certainly mention you to everyone. I suppose some think i have a bad case of hero worship ;) lol.

Fair is fair here is the book (please remove if it is inappropriate)
http://www.scottseely.com/Publications/EffectiveRest.aspx


On Wednesday, November 17, 2010 5:11:11 PM Imar Spaanjaars said:
Hi Kurt,

Not, it's not inappropriate, but posting the same message three times might be.... ;-)

Imar
On Wednesday, October 12, 2011 11:56:49 PM sofia said:
Hi Imar,
I wanna know that how much MVC is different from Web Forms. And how mch time it may take to learn this?
On Thursday, October 13, 2011 12:43:56 AM Imar Spaanjaars said:
Hi sofia,

Yes, it's quite different. However, a lot of the concepts (C# / VB, Visual Studio, .NET Framework and ASP.NET Frameworks) are all the same so you can reuse a lot of your knowledge.

Hard to tell how long it takes to learn. I would get a beginner's book, get started and then see for yourself.

Cheers,

Imar
On Friday, October 14, 2011 7:15:44 AM sophia said:
Thanks for your reply (please ignore miss-spelled name in previous post).
One more thing to ask from you What is benefit of using MVC, that you spent a lot of time to learn it and then rebuild the website based on it?
On Friday, October 14, 2011 7:51:30 AM Imar Spaanjaars said:
The reason I rebuilt my own site was purely to learn ASP.NET MVC. My old site worked fine so there wasn't a compelling reason to rebuild, other than the learning experience.

MVC has many benefits including a clean(er) routing / URL mechanism, maintainability and more. You'll find plenty information on Google about the benefits of MVC.

Cheers,

Imar
On Friday, October 14, 2011 8:11:18 AM Sophia said:
Thanks for sharing such information.
As you told that "MVC has many benefits including a clean(er) routing / URL mechanism, maintainability and more." isn't it possible such functionalities with web forms?
On Friday, October 14, 2011 8:13:46 AM Imar Spaanjaars said:
Yes, it's also possible with Web Forms. But it's harder to do it right... Or easier to do it wrong....

Imar

Talk Back! Comment on Imar.Spaanjaars.Com

I am interested in what you have to say about this article. Feel free to post any comments, remarks or questions you may have about this article. The Talk Back feature is not meant for technical questions that are not directly related to this article. So, a post like "Hey, can you tell me how I can upload files to a MySQL database in PHP?" is likely to be removed. Also spam and unrealistic job offers will be deleted immediately.

When you post a comment, you have to provide your name and the comment. Your e-mail address is optional and you only need to provide it if you want me to contact you. It will not be displayed along with your comment. I got sick and tired of the comment spam I was receiving, so I have protected this page with a simple calculation exercise. This means that if you want to leave a comment, you'll need to complete the calculation before you hit the Post Comment button.

If you want to object to a comment made by another visitor, be sure to contact me and I'll look into it ASAP. Don't forget to mention the page link, or the QuickDocId of the document.

For more information about the Talk Back feature, check out this news item.