views:

23

answers:

0

I'm learning the ASP MVC2 framework, with no prior knowledge of MVC1. At the moment I'm constructing a toy website for learning purposes.

So far I've been primarily using Html.RenderPartial as my main means of organizing view rendering. In theory I'd prefer something less imperative and more declarative.

I've read several tutorials on using display templates, model annotation, and the various Html.DisplayXXX helpers. It's nice and declarative, but I have several reservations about it:

  • It seems to break easily and quietly. When the display template encounters a property it doesn't know how to render, it just doesn't render the property at all.
  • UIHint effectively puts rendering logic in the model description. Calling it only a "hint" seems generous as it can mean the difference between finding the right template or not. This seems like an abstraction violation to me.
  • Templated rendering is susceptible search path precendence (I believe that search path order, like white space, is non-obvious information that should be relied upon as little as possible). The same can be said with RenderPartial, but I seem to be encountering issues with it more often with display templates.
  • It seems to take twice as much work to accomplish anything. I understand that display templates allow better code re-use (DRY). The reality is that in most simple websites, most models will only be displayed in one context, negating the benefits of potential code reuse.

Have you used display templates? In which applications are they worthwhile? Or have you found them to be a neat pattern that doesn't offer practical benefits?

related questions