Thomas Vestergaards stuff of doom

Web forms vs. MVC

I just finished my very first web forms project. Yes it's really true. I have never had any real hands on web forms before. When I started programming web stuff in ASP.NET I went directly from PHP5 to ASP.NET MVC Preview 2.

When I was working with PHP, I used the joomla open source CMS, which implements the MVC design pattern. Yes, MVC is actually a design pattern rather than something new fancy  stuff that Microsoft invented. Microsoft, however, did what they do best; Go all the way with their ideas which resulted in the fabulous ASP.NET MVC framework.

Anyway, what I realized, while working with the classic web forms project, was that it's quite possible to implement the MVC design pattern even though there's nothing "MVC" visible anywhere.

Consider the following as your controller:

protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
PersonRepository pR = new PersonRepository();
pR.addPerson(textfield.Value);
Response.Redirect("~/Default.aspx", true);
}
}

The controller's job is to take values from the view, and hand them on to the Model which does the actual business logic. The snippet above, takes a string from a text input field, and parses it in a repository. Then redirects the user to Default.aspx.

In the snippet above, the PersonRepository represents the Model because it is domain specific. The Model does not know anything about the view.

Using a domain driven design, is essential for us to gain the MVC pattern. But if we do so, we are rewarded instantly when we want to create unit tests for all of this. The ASP.NET MVC framework however, is a lot easier to unit test than web forms.

For me, the major difference between web forms and ASP.NET MVC, is that the horrible runat="server" tags are gone!

Praise the lord!

Comments

Web forms vs. MVC - Thomas Vestergaards stuff of doom said:

Pingback from  Web forms vs. MVC - Thomas Vestergaards stuff of doom

# December 7, 2008 11:06 AM

Morgan Cheng said:

I believe that in ASP.NET MVC View, you still need the runtat="server" tags. Otherwise, you cannot extract value from ViewData dynamically.

# December 7, 2008 8:47 PM

ThomasVestergaard said:

That is partially true Morgan.

If you want to access form values through the aspx code behind, you still need the runat="server" tag.

The ViewData dictionary is always at your service in the aspx code behind, no matter if you use runat="server" or not.

# December 8, 2008 2:50 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)