tags:

views:

53

answers:

2

When implementing a helper extension for a similar navigation widget to the one described in this article I notice that my HTML is now tied up in C# code, so if I want to re-skin the site with a new menu control that needs slightly different markup (e.g <ul class="foo">...</ul> or distinct class names for nested <li> tags) I now have to edit both the helper extension and the view.

Using a helper extension is quicker and easier, but does this not violate separation of concerns? What are your experiences of maintaining such code? I'm fairly new to Microsoft MVC so forgive me if I'm missing some point here.

A: 

I think you are right and have found similar thing. It's the quicker / easier now vs. potential future pain "if" you need to change things in the future. You could possibly make your "helper" read in a template that it uses, so you could change that, restart the web app and see your changes appear. However, that increases complexity too. I would say a lot of agile says do the easier / quicker stuff now and understand that in the future if your requirements change then revisit it then. Who knows, it may never happen.

Paul Hadfield
I agree that it's better to have a working solution now that is 80% right than to have a 100% solution that takes an extra few days but that might never be needed. Agile is great for clearing thinking. In my case I will definitely have need to reskin it a few ways. I set up a Helper function that accepts styling parameters which worked out ok. Still not entirely comfortable with HTML being generated within a compiled class though but we'll see how it works out over time. Thanks for your POV!
rargie
+1  A: 

A well-designed HTML Helper should be versatile and have very loose opinions about how it builds its HTML. You can add overridable options to the extension method so that the rendering is as configurable as necessary. If you have new requirements and your existing helper isn't flexible enough, extend it to accommodate the new requirements.

Dave Swersky