Notes on ASP.NET MVC for ASP.NET Webform Developers
So...you are a web developer who is familiar with ASP.NET Webforms. I hope you like MVC but to get the most out of it you should probably know what will not work anymore or what should not be done because it does not fit the pattern. If any of you think something needs to be added to the list, do say so. So here are various notes in no particular order.
There Is No Viewstate. There is no more Viewstate. This means you will have to maintain your own client-side state. Some will be glad to be away from it, some will not.
Server Controls Are Replaced by HtmlHelpers. The good ol' <asp:TextBox runat="server" /> stuff is gone. To get a brief look at the HtmlHelpers, take a look at the getting started tutorial about creating a form.
This does not mean that putting a server control on a page will not work; in some cases they will. It does mean that you should not, because you are just asking for problems (lack of viewstate will cause some server controls to not work correctly in MVC) and it is totally against the model of the new toolkit.
You Have No Code-Behind Files By Default. For many this will be a huge change. You can add a code-behind to View files in MVC but they should usually be unnecessary. If you get the temptation to do this, ask yourself "Is the code I want to write only related to the rendering of the Html?" If the answer is "yes", then go ahead unless it makes sense to put it in an Html helper. If the answer is "no", then there is almost always a better place to put it in MVC. Some obvious options include a) put it in the controller or b) put it in the model.
Urls != Pages. For example, there is no .aspx file at [WEBSITE ROOT]/GettingStarted/NotesForASPNETWebformDevelopers for this web page. In MVC different views could be returned the same url, so the idea that "Url Path == page on server" is no longer valid. As a general rule there will probably be one View file for most Urls, but that is not always going to be the case.
MVC Is Not A Replacement for Webforms. Both are in ASP.NET 4.0 and will be supported in the future.
Your Click Event Is Gone. Webform developers are used to slapping a button on a page, double-clicking it and getting an method in the code-behind that will execute on the server-side when the button is clicked. No more. Webforms was an object-oriented (more or less) facade over one of the "normal" bits of the web, the post. It "faked" us (though we really knew different) into an idiom that is not actually native to the idea of the web. There are some nice things about that...but that is gone.
More Inline Code. In Webforms inlining code in the page was not the norm; in MVC it is. As long as the code is just for the UI that is fine as a separation between UI and model is still maintained, though it is still a big departure.
Anybody think of something important that I missed? I am sure there are a billion important notes to make...
Speak Your Mind!
Have something to say? Find a grammatical mistake? Think I said something incorrect? Don't like my perspective? Hate my color scheme? Whatever it is, you can let me know. I would appreciate it if you did.
