ASP.NET Model View Controller (MVC) Framework
ASP.NET WebForms brought a familiar programming model to the Web by layering an eventing subsystem on top of HTTP, which as you know is a stateless protocol. Suddenly developers could drag a button and a textbox on a page, double-click and start implementing a
Button_Click handler. This makes a lot of sense given both needs and assumptions of the LOB (line of business) developer. WebForms’s familiar model was made possible by things like ViewState and the PostBack model.
However, WebForms isn’t for everyone. Currently it’s difficult to test ASP.NET WebForms applications without either automating the browser or at least firing up a Web Server to host ASP.NET. Test Driven Development (TDD), is a challenge to say the least on ASP.NET WebForms today. The WebForms abstraction can free the developer (if they choose) from worrying about markup, but that isn’t what everyone wants.
An alternative way to structure your ASP.NET applications is the
ASP.NET MVC (Model View Controller). It’s important to call out that it’s in the namespace
System.Web.Mvc, not within
System.Mvc (in other words, it lives as a part of ASP.NET, not beside it). All the same subsystems, Session, Providers, Membership, etc can coexist within ASP.NET MVC. It is an implementation of the popular MVC pattern applied to ASP.NET. It’s not for Windows Forms, and it’s not a "skunk works" project. ASP.NET MVC is a new alternative project type within ASP.NET that caters to developers who are interested in scenarios that WebForms doesn’t easily lend itself to. When released, it will be a supported and powerful subsystem within ASP.NET – you can download now the
ASP.NET MVC Preview 2.
ASP.NET MVC’s primary goals are a clean separation of concerns with the model, view and controllers all playing specific and separate roles. Views are concerned with rendering HTML and nothing else. Models don’t know about Views or Controllers, and so on. This separation helps enable not only easier testing, but also promotes reuse and refactoring.
This project is breaking new ground in a number of ways. For example, it will be hosted at CodePlex with not only its source code available for reference, but also the source for its Unit Tests! Developers will be able to get builds much faster and much more often than Microsoft has usually released in the past. You are encouraged to share your experiences and findings on blogs and
forums that the team is already engaged in.
To be clear, ASP.NET MVC won’t be for everyone. You won’t find controls as rich as with WebForms, and to some developers it may seem like a step back. It is an alternative, not the answer to all woes. It won’t always be pretty, but it sure is fun. I encourage you to follow the links above, to get involved in the conversation and to see if MVC is for you by watching for
blog posts tagged “aspnetmvc”.
Scott Hanselman
Senior Program Manager in Developer Division
Read Scott's blog
Results From Last Poll:
What programming language do you use more than others?
47% C#, 24% VB.NET, 12% C++, 10% VB6 or earlier, 7% Other.
Question of the fortnight
Most developers work on a combination of various domains, but what do you focus on predominantly:
1.
Client
2.
Mobile or embedded
3.
Server
4.
Web
5.
Database