This post is inspired by the presentation that Patrick Hynds and I gave on ASP.NET MVC at StackOverflow’s DevDays conference in Boston. Whether you attended DevDays or happen on this from the web, I hope this is useful for you to learn more about ASP.NET MVC. (Let me know if you have additions or questions.)
ASP.NET MVC is an implementation of the Model-View-Controller pattern on ASP.NET and is freely available via:
Learning ASP.NET MVC
To start learning ASP.NET MVC, go to www.asp.net/mvc/learn. There’s tutorials, videos, sample applications, etc. to get you underway.
Then, grab a cup of coffee and sit down to study the Nerd Dinner sample application. It has plenty of intermediate concepts like testing, repository, validation, and more.
- I highly recommend you work through creating Nerd Dinner with the 196-page walkthrough by Scott Guthrie
Here are some other places you can turn for more:
- MVC Cheat Sheets – Great compilation by Elijah Manor
- ASP.NET MVC Forum
- StackOverflow ASP.NET MVC Tag (which as you may know is itself based on ASP.NET MVC)
These are intermediate topics we touched on in the Boston session, and pointers for learning more.
Learning the M-V-C of ASP.NET MVC is only part of the story. Routing is what takes an inbound web request and maps it to a controller action (and arguments). There are routing tutorials on the ASP.NET site and on MSDN.
Code generation in Visual Studio is customizable via T4 templates, and ASP.NET MVC uses these as well. Need a different view or controller created in your projects? Change them or add new ones. They can change for all projects, or you can add/override them in specific projects.
Learn more at T4 Templates: A Quick-Start Guide for ASP.NET MVC Developers.
One of the key features of ASP.NET MVC is flexibility in implementation. Head to MVC Contrib to find additional options for extending and modifying how ASP.NET MVC functions, including:
- View engines
- Controller factories
- Model binders
- and more
Key Bloggers Covering ASP.NET MVC
We had good questions during and after the DevDays session and I wanted to share details for some of the key ones:
There were a few questions about taking data from a submitted page and getting it to arguments in an action method. This is well supported via model binders, which let you map posted form data to classes passed as arguments to action methods.
Learn more about model binding at:
- “6 Tips for ASP.NET MVC Model Binding” – K. Scott Allen
- Models and Model Binders in MVC Applications
- “Splitting DateTime – Unit Testing ASP.NET MVC Custom Model Binders” – Scott Hanselman
- Video – “Using ASP.NET MVC Model Binder”
Using the ViewData dictionary is one way to get data to a view, but you can also create classes to contain that data. Called the ViewModel pattern, these classes help to structure and identify the data needed.
You can learn about ViewModel here:
- “ASP.NET MVC Tip #50 – Create View Models” – Stephen Walther
- Nerd Dinner sample application walkthrough – Part 6
ASP.NET WebForms vs. ASP.NET MVC?
It’s important to keep in mind that you can mix ASP.NET MVC and ASP.NET WebForms in an application, so this isn’t necessarily an either-or proposition.
Let me know if you’ve found something else particularly helpful in learning about ASP.NET MVC. I’ll be happy to add it.