Thursday, October 23, 2008

ASP.Net MVC Framework

We've been using the new mvc framework at my company since the Preview 2 version. For those who are keeping score the beta was released about a week ago. I've been fortunate to have been able to work on projects that have spanned the evolution of this framework and had to upgrade a couple so I thought I'd share some of the highlights.

Let me state for the purpose of full disclosure that I've only been doing web development for about a year and a half though I've been an application developer for over 10 years now. But it's been a very full year and a half as I've been very fortunate to work for a company that embraces new technology. 

First of all, the mvc framework, certainly not a new idea having been around for some time, is a relief from having to deal with web forms. One of the biggest headaches of trying to incorporate javascript, for example, in a web forms app was having to use the ClientId property of html elements and pass that id back to the server rather than just using the id that I assign. This illustrates what seems to be the key feature that one would look to when considering switching development frameworks. With web forms the focus is on the server processing. Anytime you want to do client side processing you'll more than likely have to do some work around / hack to get it to work. It's not so much that the mvc framework gives you new functionality that web forms doesn't. It's the fact that you don't have to fight tooth and nail to get simple things to work. 

For example, take any web forms application and view the source of a page. You'll find all the nasty looking element ids that are auto generated along with html that, if you were the developer, would leave you scratching your head wondering where it came from. Now take that same page written using the mvc framework and you'll see ... wait for it ... yep, pretty much the same html that the developer wrote. You have control of every single tag that is written. 

Here's another gem. You have a datagrid control and you want to include a checkbox column. And to each checkbox you want to assign a custom attribute. Go ahead and try it. I'll wait. Hopefully when you get back here you won't have pulled out all your hair after you notice that each checkbox is enclosed in a span tag and your custom attribute is not assigned to the checkbox, BUT TO THE SPAN! Somebody with more experience please explain that to me. That same exercise using the mvc framework involves either using the Html.Checkbox helper function or just simply writing the input tag yourself and assigning whatever attribute you want. I'd call it What You Write Is What You Get. And while the world certainly doesn't need another acronym, if you try saying WYWIWYG a few times you'll soon be reverting to an Elmer Fud voice and rolling on the floor as I am right now. 

Excuse me.

Ok, I'm back.  If you want further information regarding the mvc framework, I'd check out Scott Guthrie's blog. One thing that does seem to be lacking, at least for now, is a good set of VB.Net examples. I say this because I'm currently working on an application for a client that requires VB.net and having heavily relied on example code to learn this new framework, I spent a lot of time trying to convert some of the features. Admittedly, though, much of the difficulty in conversion was dealing with LINQ and not specifically the mvc framework. I'll post some of the more interesting examples another time. 

No comments:

Post a Comment