Last week I presented at BC .NET user group and there are a number of good questions I didn’t have time to answer. So here’s a recap.
Download sample code here
Why would I choose ASP.NET MVC over traditional WebForms?
The answer to this question deserves its own post. So you can read it the answer here.
I’m an ASP.NET WebForm developer, how difficult is it for me to learn MVC?
Although development on MVC framework is different from WebForms, I don’t think it is difficult at all. In fact, if you are familiar with the MVC pattern, polymorphism, HTML, HTTP, and how the web works in general, you’ll feel right at home with MVC.
The fastest way to get a to know MVC is to create a new blank MVC project in Visual Studio and look at how the HomeController class, model, view (under the folder Views/Home/Index.aspx), and routing in Global.asax are put together.
From this, you’ll get the basic idea of how MVC wire things up together. After that there are a number of sample applications you can inspect:
These 3 sample applications should be able to demonstrate how you can get MVC to work and how you can effectively leverage the framework and pattern. Also don’t forget to check out loads of tutorial on ASP.NET MVC website.
ASP.NET MVC is shipped with JQuery (I believe now it’s 1-3.2 version), but you are NOT tied to the library. You can use any client side library you want. My team and I have been using MooTools for most of our MVC projects.
What do you mean when you say that ASP.NET MVC is stateless?
WebForms keep state (original values of ASP.NET controls on a page) inside ViewState. This ViewState is usually stored as a hidden field or inside a session. When an ASP.NET form does a postback, the server side then reads the values kept in the ViewState, restores the controls object model, and allows you to manipulate the values. This is the way ASP.NET WebForms tries to make the web stateful (every controls seem to remember their previous values).
ASP.NET MVC does NOT rely on ViewState. MVC view interacts with the controller (server side) via simple form post request to designated URI. All the values are encapsulated within the HTTP request. The server side controller only works the posted values and return final output of rendered HTML back to the browser.
Can I use both WebForm and MVC in one project?
Yes, you can but it is NOT recommended. In the project I’ve worked on, there are a migration period where we have to have both WebForms and MVC coexist in one project. Although it is possible to have both, it comes with a price of maintainability.
Do I have to use TDD or BDD in MVC project?
You do NOT have to do TDD or BDD in your MVC project. Test-Driven development is a good development principle but MVC is not tied to it.
How can I do databinding in ASP.NET MVC?
Please see the sample code accompanying the presentation. In the source code download, I show 2 ways of data binding, one with using <% foreach %> and another binds to ASP.NET repeater control.
Can I still use user control in MVC? Is there any 3rd party controls or components for MVC?
You can still use user controls in ASP.NET MVC via Partial Rendering. Though you may have to simplify your user control code for consistency with the framework.
AFAIK, I don’t think there’re free controls for ASP.NET MVC released just yet. But you really should check outMVC Contrib project on CodePlex, it offers a lot of helper classes that you will find very useful. On the commercial side, Telerik has released its MVC-Compatible web controls suite.
What about Ruby on Rails?
There were a lot of people showing interest in learning more about Ruby on Rails after the presentation. And I think they definitely should check it out. A lot of good ideas from Ruby on Rails community have been incorporated into MVC framework. But despite what some people would say, I don’t think ASP.NET MVC is intended to be Rails-clone.
I do work on Ruby on Rails as well and they are different. One reason that Rails is cool is because it leverages a lot of dynamic feature of Ruby the language. The only similarity I see between ASP.NET MVC and Ruby on Rails right now is the fact that it implements the MVC pattern and good guiding principles such as Convention over Configuration, DRY, and YAGNI.
If you want to learn and find out more about Ruby on Rails, it’s definitly worth check out this free online course.
Any comment or questions, feel free to leave comment on this post or contact me at email@example.com