Free ASP.NET MVC “NerdDinner” Tutorial Now in HTML

Last month I blogged about a free end-to-end ASP.NET MVC tutorial called “NerdDinner” that I wrote for the Professional ASP.NET MVC 1.0 book from Wrox Press.  The book is now released and shipping on Amazon

The NerdDinner tutorial walks through how to build a small, but complete, application using ASP.NET MVC, and introduces some of the core concepts behind it.  You can download a PDF version of the tutorial here.

NerdDinner Tutorial Now Also Available in HTML

A few minutes ago I finished publishing an HTML version of the NerdDinner tutorial as well.  You can read it online for free here.

I split the tutorial up across 12 segments to make it more manageable to read.  I also increased the sizes of the screenshots, and used a really nifty syntax highlighter that Scott Hanselman helped set me up with.  I actually find the end result a lot easier to read than the PDF version.

Below are links to the different NerdDinner tutorial segments:

Hope this helps,

Scott

69 Comments

  • Great Scott!

    Your blog is fantastic, we can find invaluable resources.
    Thanks for sharing you experience!

    Josef

  • Where does "dinnerToCreate" come from in the Create() method at the end of Step 6?

  • Scott,

    Can you post link where I can by the eBook edition when it is available? I looked on wrox.com and couldn't find it.

    If it is ready, I'll buy a copy today.

    Thanks for your effort.

  • Thanks very much.
    NerdDinner project is helpful to learn ASP.NET MVC.

  • @mgroves,

    >>>>>> Where does "dinnerToCreate" come from in the Create() method at the end of Step 6?

    Sorry about that - that was a typo. I just updated it to be "dinner" - the variable being passed in.

    Thanks,

    Scott

  • @Cody,

    >>>>>> Can you post link where I can by the eBook edition when it is available? I looked on wrox.com and couldn't find it.

    I'm not entirely sure when the eBook is going to be available. I don't think it is out just yet.

    Sorry!

    Scott

  • @Scott,

    >> I'm not entirely sure when the eBook is going to be
    >> available. I don't think it is out just yet.

    Thanks. I'm the patient type. BTW, I checked into it, and Sony published an update along with Adobe that allows Digital editions to work /w my eBook reader.

  • Scott -

    Thanks for the link. I have some feedback for you: It is difficult to find tutorials specifically for the release version that comes with .NET 3.5 SP1. I have been trying to find tutorials, and I end up finding tutorials that are geared towards pre-release versions that seem to be very different. Is there a way that your official ASP.NET site can tag tutorials based on versions?

    thanks.

  • I made a comment about the a missing space. I'm seeing that on subsequent steps as well. I'm just now working Step 5 the CRUD step. Using IE 8 to view source the line number is 232. For this one it was the MainContent only then TitleConent looks good.
    I will keep you posted if I find anymore. Again the draw back is that if I click the icon to view source then copy and paste the code will not run.

  • Here are some more with Step 5. Line 945 and 949. This one is both the TitleContent and MainContent.

  • Well I have spent the better part of my day going through this tutorial. I'm up to part 6. I will say this is awesome. This tutorial is just great. From this I can see how an MVC design cuts down on development time. I was wondering what time/labor difference to build a similar ASP.Net Forms app. To show how quickly and clean one can build simple CRUD application using MVC compared to ASP.Net Forms. I would say build an asp.net Forms app up to step 6. I have enjoyed going through the beta of the product and could not wait for the release. The release here, and now this simple tutorial is the icing on the cake. I can get developers and other on board by stepping them through to step 6. Showing how simple and quickly this can be done. I would say that was no more than 2 hours of my morning (minus the bug with spacing) Now I need to go find some business to start using this. Thanks!!!

  • Ok, this one was a bit different and did not follow the other pattern. I'm working on the delete of step 5. View Source in IE 8 on line 1199 the ContentPlaceHolderID is wrong "head" should be "TitleContent"

  • Should I assume that the code is "demo" quality, not meant to illustrate best practices. Just to show very basic demonstrations of how to use MVC.

  • For some fun me and some friends started a website called ASP Joe, as a kind of Joe Stagner fan site.... Take a look its funny.

  • Very cool, I like PDF materials! Many thanks for your hard work!

  • Hi Scott,
    Being new to Asp.net MVC, I took it out for a spin. I check out the website, read the tutorials and of course studied the NerdDinner tutorial sample. All good stuff. Armed and emboldened, I played with a few of the design templates from the design gallery. All in all a good ride and I expect an even better ride to come in the next model year. However, during my test drive I did discover a few miniscule imperfections that you may or may not be aware of or even care about for that matter. But here they are. I was surprised to see that the ChangePassword.aspx and ChangePasswordSuccess.aspx files were not wired up. Changing the LogonUserControl.ascx code to:
    if (Request.IsAuthenticated) {
    %>
    Welcome !
    [ |
    ]
    <%
    etc. did the trick simply enough. I looked at a few of the design templates from the gallery, specifically October (most popular last time I checked) and E-commmerse (the only web-store front design I saw). I followed the instructions to changing the default MvcApp theme. It didn't work out of the box (didn't really care), so I tweaked them to make them work correctly and decided to exported them as templates. When I went to use the template I noticed that they are only visible as a "C#" ("VB.net") projects, but vanish if you select "Web" project. This is curious as the default Asp.net MVC template does not vanish that way. I refactored the E-commmerse template so that the "featured products" were in a SQL database exactly like the Movies database sample tutorial. Then another curious think happened. When I selected that template and ran it, the application failed to compile correctly. It turned out (I used Visual Studio Express Ed. 2008 and Sequel server express Ed. 2008) that the link to sequel designer.cs file, although properly created, was excluded from the project. Including that file back into the project allowed the application run correctly. Now I know you are thinking picky, picky, picky! Well, yes, but maybe you wanted to know!

  • great as always....

  • @DevSlick,

    >>>>>> Thanks for the link. I have some feedback for you: It is difficult to find tutorials specifically for the release version that comes with .NET 3.5 SP1. I have been trying to find tutorials, and I end up finding tutorials that are geared towards pre-release versions that seem to be very different. Is there a way that your official ASP.NET site can tag tutorials based on versions?

    That is good feedback and some we've heard before. We are trying to take down some of the older content on our various sites and make clearer what is and isn't built with the final release.

    Thanks,

    Scott

  • @Some One,

    >>>>>> I made a comment about the a missing space. I'm seeing that on subsequent steps as well. I'm just now working Step 5 the CRUD step. Using IE 8 to view source the line number is 232. For this one it was the MainContent only then TitleConent looks good.

    Thanks for pointing out those typos - I just fixed them for Step4 and Step5. Let me know if you run into any others.

    Thanks,

    Scott

  • @John,

    >>>>>> Should I assume that the code is "demo" quality, not meant to illustrate best practices. Just to show very basic demonstrations of how to use MVC.

    In general I've tried to keep the code clean and have it show good practices. People's definitions of "best" practices tend to differ - in particular when it comes to designing model layers and integrating validation and business logic. For the tutorial I've gone with a clean but simple approach that uses an imperative code technique that is fairly common in a lot of applications. The code for paging, security, ajax and unit testing is also clean and I think a good model to copy.

    Hope this helps,

    Scott

  • @John Mortarelli,

    >>>>>> Being new to Asp.net MVC, I took it out for a spin. I check out the website, read the tutorials and of course studied the NerdDinner tutorial sample. All good stuff. Armed and emboldened, I played with a few of the design templates from the design gallery. All in all a good ride and I expect an even better ride to come in the next model year. However, during my test drive I did discover a few miniscule imperfections that you may or may not be aware of or even care about for that matter. But here they are. I was surprised to see that the ChangePassword.aspx and ChangePasswordSuccess.aspx files were not wired up. Changing the LogonUserControl.ascx code to:

    We went back and forth a little on the change password support. We wanted to have it built-into the controller so people could just use it, but couldn't find a great way to integrate it into the UI of the site in a way we didn't think was going to be annoying (we thought most people might want to have a "Account" page where users could manage their settings instead of having the change password link at the top right of every page). We shipped the default template the way it was so that people could then go in and tweak it however they wanted.

    I will forward along your suggestion to the team, as well as to the person who helps manage the design style gallery to make sure we get those updated to work with the final release.

    Thanks,

    Scott

  • Hi Scott,
    I am a student, trying to learn ASP.NET MVC. I have been trying to implement the NerdDinner following the tutorials but the "Step 10: AJAX Enabling RSVPs Accepts" doesn't work. I have installed the JavaScript intellisense hotfix for VS 2008 SP1 that enables richer intellisense support for JavaScript files and included the scrift reference provided into my Site.Master master page but still...

    This means that I am unable to add into the RSVPs table.

    I also notice that when I create a new Event it doesn't add the object into the database although I can successfully edit.

  • Your welcome. I will be continuing with the tutorial today. If I see anything I will let you know.
    - guy boicey

  • I found a typo with Part 6 relating to PhoneValidator.AllCountries. On line 82 and 143 should read PhoneValidator.Countries instead of AllCountries. The issue leads me to something the tutorial is missing or lacking. I downloaded the source code for comparison reason.



    Wehn this issue come up I was trying to find PhoneValidator.cs with the downloaded source code. My file was in a different place than the on in the download source code.



    This issue leads me to believe something migh not be clear in step 3 relating to helper functions and the PhoneValidator. There should be steps to create a seperate folder and the PhoneValidator.cs goes there.

  • Like I stated before in step 3 about creating validation helpers and how things appears to be missing. Well I can't wrap my mind around DinnerFormViewModel.

    First question, I though it was a bad design to nest or have multiple classes in one file. Why is DinnerFormViewModel in the DinnersController.cs file instead of a seperat file. To support this idea as to why this is bad. I was looking for a file called DinnerFormViewModel.cs but could not. I had to open the project in VS2008 use the Class View to find the class in the DinnersControlers.cs file.

    Second question, I can't understnad why it is in the controller folder becaue it is in a controller .cs file? If this class was seperated out form the controller where would it go. To generalize the question, when one build a ViewModel class what layer or section does it go Controller or Model or someplace else. I see Model in the class name, would the Model folder be a better fit?

    As the tutorial is written it seams that the ViewModel pattern is optional. Because you show two, and the ViewData Dictionary worked and was simple. So why implement the other, I will just read about. The implementaiton seems to be more informitive and lacking the steps to implement it into the tutorial. How to transition out of the ViewData pattern and replace with the ViewModel pattern. For simplicity I skipped it only to find out it was a bad move.

    On Step 7 the ViewModel pattern is required. I'm going to build my using a seperate file and placing in the Model folder. I will let you konw how it goes.

    - guy

  • Towards the end of step 7 one is to replace the header of the Master Template. I don't konw if this is a typo, becuase in the d/l code the filename matches the code. But based on the skeleton project built from VS2008 the file name is different. The file name in the final build (d/l code) is LoginStatus.ascx. The typo is at line 388 of Step 7. I replaced that with the one VS2008 created, LogOnUserControl(.ascx) whith out the file extension. It seems to work.
    - guy

  • Now I'm on Step 8 and like Step 3 there are helper classes. But again the tutorial does not instruct on where these go.

    Also the section to add the Navigation Links to Index.aspx is incomplete. The page Inerits from a different class:

    System.Web.Mvc.ViewPage<NerdDinner.Helpers.PaginatedList>

    Instead of

    System.Web.Mvc.ViewPage<IEnumerable>

    That needs to be done before running the application.

    I think I'm done for the day. I will pick up where I left off tomorrow. I will keep you posted on any other changes.

    - guy

  • When I right click and choose 'Add View' in part four under Implementing the "Details" View Template, I don't get the option to define View Content. Why is this? I have .NET 3.5 sp1 installed. My View is unable to resolve the Model.

  • Thank's for the html version. The pdf is very handy though.

  • Thanks Scott. Really great jump start tutorial. I'm having a couple issues I think have to do with the latest version of JQuery (1.3.6). The RSVP message animation doesn't enlarge, map positioning isn't behaving (always docked in the upper left hand corner of the browser and covering my input fields -- tested in IE and Firefox 3), and the map doesn't update latitude/longitude values correctly. Has gotten any of these to successfully work with JQuery library included w/ the latest version of MVC?

  • Scott,

    You always call ToList() on your IQueryable objects before passing them back to the controller response. I couldn't find the rationale for that in the text. What are the advantages of doing this, as clearly it means that items have to be traversed twice, and a (somewhat unnecessary) List object built in memory?

    Thanks.

  • Thanks Scott. You have been a great inspiration so far.

  • I'm having a rather strange problem. I cannot attach a new database to the project. I follow the instructions you have provided for adding a database to the project (I've done this a million times before), but VS2008 says that Sql Server Express needs to be working correctly and that I should check my installation. I have Sql Server 2008 installed. Anyone else seen this?

  • Thanks for sharing this. It is much appreciated.

  • The book is cool. I will definitely read offline version on weekend.

  • I pre-ordered the book from Amazon.com and it arrived a couple of days ago -- FANTASTIC! Chapter 1 - Nerd Dinner Tutorial -- A.K.A. the first half of the book :P -- is absolutely great! Even though I've already been using the online version, I'm glad I bought the book as well. The other authors (ScottHa, Phil and Rob) added a lot of additional "under the covers" understanding about how ASP.NET MVC does what it do. Thanks much.

  • Scott, just one minor point -
    Part6.htm creates a new SelectList using "PhoneValidator.AllCountries". In Part3.htm however, this property is simply defined as "Countries". The pdf is correct on this.

    Overall, this has been very helpful and well-written tutorial. Thanks for making this available!!

  • Hi Scott, You are doing a fantastic job positing such a detail explanation on getting started with new technologies. Even i tried doing that though but i could not able to achieve 100% on providing each and every image as it is time consuming. Can you please provide me some details on what tools you use for images and for generating code snippets in your blog???

  • Hi scott,
    Thanks for a great article. I have a question though. Is it possible to combine ASP.net web forms with ASP.net MVC model so that we can also utilize the web forms .Net UI controls along with the power provided by MVC?
    Thanks.

  • I'm working through the tutorial and rewriting it in VB.Net. One issue was with the Dinner.GetRuleViolations function. I ended up rewriting it as:

    Public Function GetRuleViolations() As IEnumerable(Of RuleViolation)
    Dim violations As New List(Of RuleViolation)

    If (String.IsNullOrEmpty(Title)) Then
    violations.Add(New RuleViolation("Title required", "Title"))
    End If
    ...

    Return violations

    End Function

    Seems to do the job. Any comments?
    P.S. I also rewrote the helper class to have a New sub with the two parameters.

  • Thanks for this tutorial, it's amazingly valuable for me. I've been playing with the idea of taking a look at ASP.NET MVC, and this helped me a lot in making the first step.

    Now that I've gone through the NerdDinner I'm seriously thinking of buying the book.

  • I'm adding the VirtualEarth code, and the map is positioning top left, rather than in the desired position. If I download the source code (rather than build through the guide), it works. So far, I've compared most of the relevant code (Map.js, Map.ascx, DinnerForm.aspx, ..) and found no differences. Javascript version is different (1.3.2); Web.Config is different. Any idea?

  • Hi Scott, thanks for giving this cool tutorial. I've just glanced through it. Sounds interesting. I'll go through it fully during this weekend and come back with more comments.
    Thanks once again.

  • Very cool,

    I'm looking forward to getting started with MVC. Thanks for posting this.

  • I truly love your blogs, Scott as it contains so many useful information that aid me in learning about new stuffs in ASP.NET. I bought a book about ASP.NET MVC at BORDERS book shop, start to learn new things and I have just just completed it.

    After doing an extensive research, I host this site at ASPHostCentral.com (http://www.asphostcentral.com) as this host provides the latest ASP.NET MVC hosting at a very afforable rate. After all, my site is up and running on their Windows Server 2008 environment with no problem at all. Hope I can learn more things in the future...:)


  • Thank you... I love you.

  • Scott, I wish I had found this tutorial sooner! I've been working on an ASP.NET site for my Uni senior project. If only I had know about the MVC framework my site would probably be done by now. I'll probably get a copy of your book for my personal development in the future. Thanks!

  • Hi, the walk through chapter for Nerd Dinner is great.

    I have been running through it and was wondering why at page 99 we are still using a helper method of ModelState.AddRuleViolations(...), but then at page 103 it switches to a helper method of ModelState.AddModelErrors(...)

    Is this just for semantics?? because it was a bit confusing when I first saw it.

  • nice tutorial thanks for sharing with us

  • The e-book is up there on the Wrox site, same price as the "real" book.

  • Step 3 - dinner.RSVPs - no such definition for me.....

    public void Delete(Dinner dinner)
    {
    db.RSVPs.DeleteAllOnSubmit(dinner.RSVPs);
    ...
    My DB & dbml design looks ok as far as I can see.
    Any help appreciated.
    Thanks

  • Step 3 - dinner.RSVPs - no such definition for me.....

    Sorry....spotted error of mine! Missed PK from my child table, so definitions were not created automatically.

    Thanks

  • Hi,
    Thanks for this, it is very much appreciated. I will definitely buy the book and will do extensive research on the same.

  • Hi Scott,

    Posting here for the first time. Had a question didnt know where to post.

    Why hasnt starter kits been updated and why is the quality of them so crap.
    compared to php where you have magento ,oscommerce the development time gets reduced dramatically.

    I know about nopcommerce,dashcommerce and other things but even afte using them development time is much much higher compared to php.

    I think there needs to be some effort made for creating apps that are targeted for small to medium sized sites.

    I love .net been working on it for 3 years and now it seems that i dont have a choice but to learn php because of the ease of developing application in them.

  • If anyone is having issues with the function "callbackUpdateMapDinners" and you copy pasted the code from the HTML tutorial, it is missing the closing brace.

    Cheers!

  • Cheers Scott!

    Another great update and again some more great advice!

  • Hi Scott, you seem too obsessed with the word 'free', most of things linked on a blog/between the community are. Too much emphasis for a otherwise great non-profit initiative of you, just wanted to point it out because you see, it sounds forced charity after the 11th mention of the term.

    I am an avid reader of this site, doing wonderful (and control-freak) things with MVC, so I won't let my bit of criticism overshade the great things being done, but sometimes we are just too much into our worlds we escape the reality (a good thing mostly!)

    Regards,
    Francisco

  • Hi Scott

    Good job on the tutorial!

    One question, where can I find the NUnit extensions for ASP.NET MVC.

    Thanks

  • Thanks Scott for the tutorial, you are always helpful :)

  • Should we derive any significance from the fact that you're still using Linq To SQL in your examples instead of the Entity Framework?

  • Thank you very much!

  • Just to point out that in Step 6 the first ViewModel Edit method has a [Authroize] attribute, which I think is a typo.
    This made me spend couple hours figure out why all of a sudden changing from ViewData to ViewModel causing authentication .... ;=)
    Anyway, I will keep going to Step 7

  • Great that you went to all this effort. It's great to have this in an easy to search format and also having the source code using Syntax Highlighter.

    I use the same thing for my blog posts, I agree, pretty nifty ;)

  • You know, my dear friend, i have paid attention on this page for a very long time, and i have found a lot of interesting things here too. You are so cool! words fell me to show my respect to you! So i want to learn more about you and want to get more from your page, please do us a favor, put more on your page. We are looking forward to seeing the update!

    Best regards and have a nice day!

  • I've looked at MVC and MVP patterns off and on for the last year and I cant help but draw the conclusion that for a clear separation of the UI from the underlying implementation MVP seems much better. I'm positive that this is my lack of knowledge about the implementation of both patterns so could you direct me to good articles introducing each pattern as well as information on why MS decided to push MVC so strongly.

    Cheers

  • This has been really helpful to me for learning MVC, and people have actually commented on how quickly I've had a fully functioning site up and running. Excellent job!

  • Excellent tutorial!!!!!!
    Congratulation

  • Thanks for the tutorial. I never use asp, with this tutorial I will learn about that more from now. I need more information about that step by step. Would you help me?

  • The validators in the NerdDinner tutorial change the style of the control they're validating. I think you're doing this with the HtmlHelper class. I'm curious if you can do the same with a Web Form validator control. That is, can I change the style of an input control when the validator fails?

Comments have been disabled for this content.