Practical ASP.NET

ASP.NET MVC for the ASP.NET Programmer

Peter begins a series on educating traditional ASP.NET developers in the latest version of ASP.NET MVC. But first he looks at why he is not an ASP.NET MVC developer.

I'm an ASP.NET developer with only a passing interest, right now, in ASP.NET Model-View-Controller (MVC). I don't even have a good feel for what the adoption of ASP.NET MVC is like -- though I do know that bookings for Learning Tree's ASP.NET MVC course are creeping up to match the bookings for the ASP.NET course that I wrote for the company.

But if you're wondering what ASP.NET MVC is and whether you should be moving to it (i.e. assuming that you aren't currently using ASP.NET MVC) then this column and the next three are for you: An introduction to ASP.NET MVC for the (traditional?) ASP.NET programmer.

There are, as near as I can tell, three benefits to ASP.NET MVC. First, it gives you more control over the HTML being generated. This is a low value benefit to me as I count on hiring or partnering with people who have deep knowledge of HTML and CSS. The contribution that I make to my clients is expertise in application development, which is a full time job. ASP.NET development is one part of the package that I provide (the other components being database design, UI design, middle-tier business object modeling/implementation and SOA design).

The second benefit is, however, high on my list of value-added benefits: Test Driven Development (TDD). Testing an ASP.NET page is a labor intensive activity because someone has to write up a test plan and then sit in front of a computer interacting with a page to determine if the page behaves properly. I try to move as much logic as possible out of the page into my middle-tier business object in order to automate as much testing as possible, but inevitably my ASP.NET pages end up with some code that has to be validated. Indeed, any changes made to the business objects called from the ASP.NET page would require re-executing the tests on the ASP.NET pages that use those objects.

In ASP.NET MVC, the goal is to create a set of objects that manipulate the UI (the View) but can be tested from other code independently of the View. The View itself is either so spectacularly stupid that it's inconceivable that it could fail and so doesn't need testing, or can itself have much of its testing done in some automated fashion.

The third benefit is the "separation of concerns" object and is tied to the previous one: since the View is separated from the rest of the objects manipulating the presentation layer, it's conceivable that one View could be swapped out and replaced with another View (replacing a View page aimed at a Web browser with a View aimed at a mobile device or a Windows Form front end, for instance). My guess is that this is only possible by using a very smart View that would take advantage of the new environment or delivering a new View that fails to take advantage of the new View's environment. A smart View violates the benefit of TDD and a dumb View would just annoy users.

There are other benefits. It's likely that the ASP.NET MVC paradigm better supports code generation at the application level so, if you're generating applications (read: Dynamic Data) you'll find it easier to create ASP.NET MVC applications than ASP.NET applications. Not much of a benefit for a full-time developer, though, who is hired by people who don't want their application generated automatically.

ASP.NET MVC also makes extensive use of routing, which I've praised before (for .NET 3.5+ here and for .NET 4 here), but can also be used with ASP.NET.

This sounds unnecessarily negative. While I think that the idea of swapping out Views is foolish with the present technologies, that doesn't mean it will always be so. People who do want control over HTML will value that. And, quite frankly, supporting TDD more effectively is a compelling argument for me, all by itself.

So why haven't I moved to ASP.NET MVC if TDD means so much to me? Because, in my experience with the first iteration of ASP.NET MVC, I found that creating applications was so labor intensive that whatever benefits I got from using TDD were wiped out by how much less productive I was going to be in this environment. There's another reason that will become cleared in the next column: the ASP.NET MVC model matches well to a Service Oriented Architecture.

But that was then, and this is now. There's a new version of ASP.NET MVC out and I'd be an idiot not to look at it. So that's what the next three columns will be doing: educating ASP.NET developers on ASP.NET MVC 2.



About the Author

Peter Vogel is a principal in PH&V Information Services, specializing in ASP.NET development with expertise in SOA, XML, database, and user interface design. His most recent book ("rtfm*") is on writing effective user manuals, and his blog on technical writing can be found at rtfmphvis.blogspot.com.

Reader Comments:

Thu, Oct 7, 2010 Clinton Gallagher virtualCable.TV Milwaukee County, WI

Quite frankly, a full-time developer who is hired by people who don't want their application generated automatically is not working for very smart customers. You know what they say about birds of a feather :-) This manner of application development has been a long time coming as I remember Bill Gates postulating during the late 1980s. I think Peter's bias stems from fear of inherently knowing what is coming next knowing he will finally have to learn to become a competent application developer that has finally confronted his fear of the complexity of coding a user interface which has been much more challenging than hiding out in the comfort of the code behind.

Fri, Aug 20, 2010 Peter Vogel Canada

Cygnet: A comment this terse is hard to interpret (grin). However, "proper" is a very relative and subjective term. It's not clear to me that interacting through GUI driven Windows is more "proper" than interacting with a computer through a command-line interface. Given that computers are command driven, you could make a case that the CLI window is more "proper". But what we do is create simulated environments that make us more productive: We get the computer to interact with us on our terms. After all, HTTP and HTML are human constructs, not something in some way native to computers. Having created that environment we can go on to create whatever other environment we want. It's like relational databases: the data is not, in fact, stored in tables--the RDBMS just makes it look like that. The proper form for the data is a string of bytes on teh disk.

Thu, Aug 19, 2010 Cygnet Infotech Ahmedabad

To get the best softwares generated..application has to be the generated in the proper form

Wed, Aug 11, 2010 Peter Vogel Canada

I suspect Mike's comment was to begin "ASP.NET MVC is a far better..." And I tend to agree that one of the goals of ASP.NET was to make Web development look as much like Windows forms development as possible. In fact, it's amazing how much Microsoft succeeded in that goal. As both Brian and Mike point out, client-side programming is easier in MVC though, having said that, ASP.NET 4 goes a long way to improving client-side programming in ASP.NET. However, as Brain points out, there's still a lot of typing involved. I wonder if Razor will get that down to a level that makes me as productive in MVC as I am in ASP.NET. For me, the REST argument isn't as compelling as it could be because the routing that makes the REST interface possible is also available in ASP.NET (see my earlier posts on using Routing). One last note: I am writing this series with ASP.NET MVC 3 though that won't really become obvious until late in the series when I start using the HTML helpers.

Tue, Aug 10, 2010 Mike Gold

ASP.NET is a far better architecture for Web development, and not just from a nice client server separation. If you are developing enterprise applications, this is the way to go. Classic ASP.NET tried to turn the web into a windows development platform. Unfortunately, in a request/response architecture this works really badly. MVC gives you a nice REST like model to develop your client/server application. And if you are really familiar with JQuery or ExtJS then you can really make awesome, responsive web applications that don't try to circumvent the request/response model inherent in http

Tue, Aug 10, 2010

Check out ASP.NET MVC 3

Tue, Aug 10, 2010 Brian B

I've read numerous blogs comparing ASP.NET vs MVC. Seems like everyone has drunk the kool-aid except you! Bloggers are pretty emotional people it appears. lol Due to a client issue, my new project is MVC and I have been studying it for the past week or two. Man, it's a lot of work. I agree that having control over the HTML is nice, but I'm back to coding in ASP all over again. The MVC improvement is that has lots of helper classes to make this easier. These are great to have, but it's still so much more typing than ASP.NET. One MC argument that doesn't work for me is the separation of concerns. Yes, people do put business logic in the pages when it should be in a separate layer. But that's your choice. Guess what- you can do the same in a View. It's not recommended of course, but you can put any business logic you want in there and be just fine. It's the developers job to write good code, both tools will let you do whatever you want. What I LOVE about MVC so far is jQuery. Man, it's so much fun having complete control over the client side interface. Yes, you can use jQuery in ASP.NET web forms, but good luck with the way it butchers every control name. Since MVC has control over the HTML, VS.NET doesn't muck around with the names any and using jQuery is a breeze. It's really fun too! Unfortunatly, my productivity has died on this MVC project. Yes, most of it is due to the learning curve and this will get better over the next couple of weeks. But hand-coding every page is really just a lot of mind-numbing, time consuming work. No way around it that I've found yet.

Add Your Comments Now:

Your Name:(optional)
Your Email:(optional)
Your Location:(optional)
Comment:
Please type the letters/numbers you see above