Framework Madness!

And other adventures C# and asp.net …

Data Annotations : ASP.net MVC 2 Preview 1

with 4 comments

That title is a mouth full.

Moving on – if you don’t know by now the Asp.net MVC team posted their first draft of v2 last night along with a few blogs posts and a Scott Hanselman Channel 9 video. And while the first hint at Areas looks incomplete, the work on Data Annotations looks very promising.

I have been doing a major eCommerce project at work leveraging ASP.net 3.5 Dynamic Data along with Entity Framework for the admin. Using Dynamic Data has really cut my development time and I couldn’t fathom leveraging MVC without similar support. Well, MCV v2 Data Annotation support thus far appears similar but stripped down like the MCV types like it. Support comes from several improvements:

  • Display and Editor Templates: these are user controls that can be used to create display and editing output for properties specified by Data Annotations applied to the model. These are similar to field templates. However, they can be used for more than just values types, you can make controls for complex types as well.
  • Strong Typed UI Helpers: these extensions of the Html object inside a view not only allow for using lambda expressions for specifying output but also act as the gateway to leveraging Display and Editor templates. And of course using lambda expressions adds compile time support.
  • Data Annotation Validation: model validation now supports data type validations in the controller and returning the same view returns the correct validation error messages.

This really gets my interest in MVC going. The lack of controls is frustrating but I could live with out them. I cannot however live with out Data Annotation UI and validation support so this makes MVC much more approachable in the near term. The rest of the details are in the revised road map.

It looks like future previews will improve on all current features and add a few additional things to boot. How much get’s added to MVC v2 ultimately will be limited by the teams stated goal of being on the  VS 2010 DVD which will probably ship next spring.

More information:

Advertisements

Written by Lynn Eriksen

July 31, 2009 at 6:39 am

Posted in Uncategorized

Tagged with , ,

4 Responses

Subscribe to comments with RSS.

  1. What exactly do you mean by lack of controls? Do you mean you’re looking for controls similar to what you have in System.Web.UI.WebControls? I for one, think the HTML helpers are a much better choice than server-side control classes that attempt to maintain state. The web forms controls just don’t make any sense in the context of HTML, which is supposed to be stateless. I think one of the goals of ASP.NET was to go in a similar direction to Rails, providing helper classes that essentially do nothing more than generate client side content strings for you (typically HTML + JavaScript). It might be cool to see some of the HTML helpers implemented as custom tags. However, I for one would not want anything to do with control classes that are like ASP.NET web form controls. Web forms was an interesting idea 8-10 years ago, and it was certainly heavily adopted, but in practice, it feels unnatural when coming from other web development platforms (Rails, J2EE, ColdFusion, PHP, etc) because of the stateful server-side controls, and worst of all, web forms are very difficult to test.

    Justin Holzer

    September 22, 2009 at 1:52 pm

    • Justin – thanks for the input. I have been playing around with MVC 2 Preview 1 extensively for the past few weeks and I could not agree more. The concept of extending the HtmlHelper object is simple yet effective, and to be honest I don’t find my self missing the controls form System.Web.UI.Controls at all. That said, a lack of controls could be a sticking point if you were working with a designer that wanted to get satisfaction out using a WYSIWYG surface. I am guessing that, like you say, eventually the core helpers could be implemented using tag-based markup for design friendliness. It will be interesting to see what changes abound in .net 4 beta 2 that could allow for the creation of mvc controls on a severe diet in the near future. But the great thing about MVC thus far has been that control creation is is no we required, which makes for a very productive environment.

      Lynn Eriksen

      September 22, 2009 at 2:14 pm

      • You bring up some valid points. I did not really consider a WYSIWYG edit, since I typically don’t use one, but that is certainly something that would be a big help in UI design. I have always been a fan of prototyping using the same platform that the end product will be developed for, rather than doing plain HTML and JS. A good WYSIWYG editor would make prototyping much quicker for sure. I don’t think any additional objects are necessary for adding WYSIWYG functionality. It’s simply a matter of building out the editor to make use of the HTML helpers. I’m hopeful that if MS really puts their full support behind the MVC framework and starts pushing it as the preferred method for developing web apps, that we will see greater integration with Visual Studio in the future.

        Justin Holzer

        September 22, 2009 at 2:39 pm

      • There are several interesting things I have noticed in the Asp.net MVC 2 road map:

        Goal to ship along side VS 2010.
        Support for VS 2008 and VS 2010.
        Major road map items are code or project level in nature
        MVC 3 will take a dependancy on VS 2010.

        Looks to me like MVC 2 will complete the ideas started in v1, and v3 will have the opportunity to expand into new areas.
        I am not sure if the editors can parse the helpers as these are complex surfaces and have specific interface requirements. And besides, script-like parsing is something that Dreamweaver does and it is a real disater. It often grinds out even on my Core 2 Quad at work when working with .asp pages.

        But it will be interesting to see what changes to make to the System.Web.UI namespace. I am guessing that there will be new classes and design time support to pave the way for simpler controls. But I also don’t think they will look to supplant existing code mechanisms or offend the target audience. What ever they do, I’m pretty sure it will be an option.

        Personally, the html extensions make me happy. But for the sake of adoption and dev/designer interactivy I would hate to see System.Web.UI.WebCotnrols being the only WYSIWYG game in town.

        Lynn Eriksen

        September 22, 2009 at 3:57 pm


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: