Recently I started using ASP.NET MVC for a real project. SO far I had been reluctant to use ASP.NET MVC as it meant giving up on the post back model that so many of the available ASP.NET controls depend on. Yet a lot of people I know and respect where saying good things about ASP.NET MVC so I decided to try it out on a small but real project.


Well the project isn’t finished yet but I am a convert [:)]

Using ASP.NET MVC is much nicer that I expected it to be. Sure the post back model, and with it a lot of controls, are gone but I started doing more client side stuff using jQuery and the many plug-ins available. And even where not doing a lot of client side work ASP.NET MVC makes live quite easy.

The main difference is that ASP.NET MVC lends itself very well to test driven development. Now I not a pure TDD zealot but covering a lot of the code with unit test, regardless if you create the test first or later, is pretty much a requirement of a good software project. And ASP.NET MVC lend itself much better to unit testing than ASP.NET web forms.

ASP.NET MVC will not be the thing for everyone. If you are heavy into designers and drag-drop development web forms will be a better match for you. But if you are like me and like working with code ASP.NET MVC is a joy to work with.

The book I keep by my side is Steven Sanderson’s Pro ASP.NET MVC Framework. It has been very valuable, both on giving me a behind the scenes insight and solving some practical issues I ran into.





2 thoughts on “Using ASP.NET MVC

  1. Hi Hans,

    I don;t like the way RenderPartial() puts all the code back in the View. In V2 this will become better with the RenderAction() option though.

    Another think I don’t like is all the magic strings. Like where you specify the controller and action names as strings. Again something that seems to be better in V2.

    Another thing is that master pages don’t have an controler and action. I need to generate a data driven menu and that is not write as nice as I would like. Something that would be fixed by using by using RenderAction().

    But I guess my biggest pain point so far is data validation. If I create an action method using a model as parameter I can use ModelState.IsValid to check if validations pass. But using the same code from a unit test won;t work because ModelState.IsValid depends on the model binders. Using a FormCollection parameter and a TryUpdateModel() that seems to work better but it is still dangerous because validation is only triggered for properties that where actually in the FormCollection. So adding properties with validation might cause ModelState.IsValid to be true while the data is invalid just because the new property isn’t in the view being posted.

    But all in all I am pretty happy with the MVC version 1 and for this project it seems to work a lot better than WebForms. And if I add the futures assembly a lot of my “issues” should be history. Now if only the validation was better 🙂 BTW What is your validation strategy? using xVal client side and IDataErrorInfo on the server?

Leave a Reply

Your email address will not be published. Required fields are marked *