ASP.NET MVC Is My Shrieking Electric Guitar
Monday, October 20, 2008   

This is your HTML markup:

Clean HTML markup

This is your HTML markup on drugs ASP.NET:

Traditional ASP.NET markup

Any questions?

ASP.NET offers a lot of horsepower, especially in its most recent incarnation. I give you jQuery, AJAX, Dynamic Data, control adapters, and more.

But traditional ASP.NET web pages are littered with cruft: hidden fields, obscure Javascript, and a ubiquitous <form> element even on pages which don't look, act, or talk like forms. The ASP.NET WebForms infrastructure extracts a price. That price is the sanctity of your generated markup.

We could almost call clean markup the sacrificial lamb of ASP.NET WebForms development. It's what you give up in order to achieve the illusion of state in that stateless medium known as the World Wide Web. If you develop in ASP.NET, then you've probably spent a lot of time chasing your tail as I have, ferreting out how to clean up ASP.NET-generated markup to make it palatable:

But the problem with these hacks techniques is that they attack the symptoms, rather than the cause.

Dense, encrusted markup is the natural result of trying to graft a desktop application development paradigm (with events and easily recallable state and so forth) onto an inherently stateless, request-response medium: the World Wide Web. This is what ASP.NET tries to do, and that it succeeds at all (and it does succeed) is a testament to the ingenuity of the ASP.NET development team.

Still: the generated markup is ugly and loaded with boilerplate. There can be no arguing with this, although for most line-of-business applications, it doesn't matter. A little extra markup doesn't hurt anyone, neither in the transmission over the wire, nor when the Google spiders come crawling. (Although in some worst-case scenarios, unbridled viewstate has been known to grow to a few megabytes in size).

But if you're a stickler, a purist, or if you're building something that needs to be lean and mean, a typical ASP.NET WebForms application just doesn't give you the fine-grained control that you'll want—at least, not without a lot of extra work.

Enter ASP.NET MVC

You've probably heard about ASP.NET MVC by now (the official beta was released just a few days ago but the previews have been around for months) so I won't rehash.

Instead, I'd like you to take another look at that first picture, a picture of what HTML markup looks like in the land of Perfect:

Clean HTML markup

When I see markup like that, well, in the words of Led Zeppelin:

Hey, hey, baby, when you walk that way
Watch your honey drip, cant keep away. 

The above is actual markup generated by an ASP.NET MVC website. It's still ASP.NET—ASP.NET is now a superset which includes both the WebForms and the MVC paradigm within it—it's just not ASP.NET WebForms.

And it's clean. It's tight. It can be applied from the ground up, or grafted into an existing ASP.NET WebForms application. It's works with AJAX. You can still use server controls. You still have a design surface. Master pages. User controls. All that stuff still applies, if you want it.

But it puts you back in the driver's seat, rather than driving you around in the back seat. In the words of Scott Hanselman:

I like to think of ASP.NET MVC as the raw, acoustic version of the more heavily produced and multi-layered ASP.NET WebForms we use today.

Though when it comes to that, I like to think of ASP.NET MVC as more of an electric guitar, and you, the programmer, are the guy rocking out a Machiavellian riff with his shirt off, hair flying every which way, crowd-surfing, making love to the floor, whatever. And ASP.NET WebForms is the full 32-track 88-key digital production workstation with virtual instruments, effects, and those nifty little LED readouts.

But don't use ASP.NET MVC just because it's sexiest thing since sliced bread. Don't use ASP.NET MVC because it's what will get you the girls, even though I promise you it will. Use it because it works. It works so well that I've made a promise to myself and I hope it's one you can get on board with:

I will never again embed a form tag into a web page that's not intended to be submitted.

If that, if on nothing else, we should be able to agree.

Rock on?


Posted by James Devlin   31 comment(s)

SEARCH

COMMENTS

If MVC was around back in the day, maybe I would not have given up Microsoft development for good. Now that I've tasted Linux and Mac, there's really no going back though.

Deadprogrammer on 10/20/2008 11:24:15 AM (78 days ago)

I'd use anything if it got me the girls. So screw any other reason ASP.NET MVC is for me!

Poker is Rigged | Forums on 10/20/2008 11:24:39 AM (78 days ago)

Lovely stuff. Can't wait to get started.

jammus on 10/20/2008 11:30:36 AM (78 days ago)

Thanks for the post!

Terry Smith on 10/20/2008 12:37:17 PM (78 days ago)

Cool, I may just give MVC a spin, in this case.

JamesHip on 10/20/2008 3:44:57 PM (78 days ago)

Good writeup on cleaning up ASP.NET.

An interesting implementation using MVC is Kigg - a Digg clone although what is on Codeplex doesn't work with the latest releases.
I have a (somewhat) working version out at http://www.theburnlist.com/

Keep the good pokerbot stuff coming!

Dave

Dave R on 10/20/2008 3:47:09 PM (78 days ago)

The Kigg demo is a good one. I looked at this back in Preview...3? 4?

http://www.codeplex.com/Kigg

Rob Conery also has an excellent MVC storefront sample:

blog.wekeroad.com/.../

And for those who are just getting started, the TaskList demo is a good introduction:

http://www.asp.net/Learn/mvc/tutorial-01-cs.aspx

James Devlin on 10/20/2008 4:17:00 PM (78 days ago)

I hate Led Zeppelin.

Anonymous on 10/21/2008 2:13:26 AM (77 days ago)

I love Led Zepplin.

holysmokes99 on 10/21/2008 11:17:46 AM (77 days ago)

Should we be scared as PHP Jockeys?

Popo on 10/21/2008 2:44:06 PM (77 days ago)

...Some people never wrote a form tag
while building enterprise level web apps
with rapid application development mvc frameworks
like http://www.atk-framework.com/ (secret tip).
I love Pet Shop Boys...and its not a shame Wink

Popo on 10/21/2008 2:53:52 PM (77 days ago)

Great post. A little light on the information but I like that you've accentuated what to me is the selling point of ASP.NET MVC, that's CLEAN MARKUP. I could give a damn about test-driven development. I could give a damn about clean separation of concerns. Just let me output clean markup so my PHP buddies stop throwing stones.

Anonymous on 10/21/2008 11:13:00 PM (76 days ago)

PHP produces clean markup? Gasp. What version are you using?

Ed K. on 10/22/2008 6:27:52 PM (76 days ago)

Upvoted just for the pic of Jimmy Page

Ed K. on 10/23/2008 8:57:10 PM (75 days ago)

@Ed K.: PHP doesn't produce any markup on its own. Granted, the language itself looks horrible (even though I'd rather that instead of the mixed form\runat fest). At least it doesn't require HTML hacks like ASP.NET does out of the box.

It's great to see stuff like this around. Thanks for the post!

Anonymous on 10/26/2008 5:37:00 PM (72 days ago)

Has anyone else gotta a threatening email from Pokerstars about Coding the Wheel?

JagBot on 10/27/2008 9:28:11 AM (71 days ago)

They threatened to break my knees.

Vince Offer on 11/3/2008 10:19:50 AM (64 days ago)

It's been 20 days since this article was posted. About time for Daniel Radcliffe to start posting here again. He still hasn't told us if he's boned the chick who plays Hermione yet.

Terry Smith on 11/10/2008 12:38:48 AM (57 days ago)

I really hope this website is not dead, but without a post in the last month I fear the worst. RIP Coding the Wheel?

Adam on 11/19/2008 12:27:14 AM (48 days ago)

I'm hoping he's off on some secret mission...

Terry Smith on 11/22/2008 3:59:20 PM (45 days ago)

JagBot - PokerStars sent you an email?

I spent about 2 mos part time building off of the stuff here and I'm at the point where the entire gamestate in pokerstars is captured in a class. So I have all of the communication and game logic in there. But have been stagnating on the poker part of it.

Which leads me to my point... In lieu of creating an entire bot that plays for you unattended, it may be better to just make an assistance bot. Something that allows you to play more tables. So if you are a guy who can play 4 tables comfortably, you can make a preflop only bot so you can play 12 tables. That way you are always at the computer and you don't have to worry about CAPTCHA.

Anonymous on 11/23/2008 12:49:27 AM (44 days ago)

this post, dont dead.


go jamesss

alex on 11/23/2008 4:51:43 PM (44 days ago)

Lost my last 25 bucks, while playing drunken Wink

...but now Im really able to hit the micros.

Will reaching homless state Wink...

...so where are the news about building a pooker bot?

...of course Im doing some seriouse cooding stuff too. Wink

c. u.

popo on 11/28/2008 4:31:30 PM (39 days ago)

Dude! Where are you? It's been almost two months!

Terry Smith on 12/8/2008 6:33:42 PM (29 days ago)

2+2 forum members kidnapped him...

Anonymous on 12/9/2008 9:26:15 AM (28 days ago)

Would believe he is catched by some poker vendors
with an offer could not be rejected Wink...hu hu hu.

popo on 12/13/2008 9:26:24 PM (24 days ago)

Two full months... I hope you're doing good and just decided to stop posting for a while for whatever reason. Take care.

D on 12/18/2008 6:52:46 PM (19 days ago)

Or the greatest bluff of James D. whuah ha ha...

popo on 12/22/2008 1:06:54 PM (15 days ago)

merry christmas
feliz navidad

from peru


james devlin.

alex on 12/24/2008 2:25:29 AM (13 days ago)

Geez, you're in PERU? Well, Merry Christmas anyways!

Terry Smirth on 12/24/2008 3:22:12 PM (13 days ago)

This page will be the last one I'm affraid :\

Well it was good the time this site was alive.

Thanks for the tips Smile

Regards

Anonymous on 12/24/2008 8:42:36 PM (13 days ago)

Comment on this post:

Thanks for your interest in Coding the Wheel. All fields are optional.