Skip to content Skip to sidebar Skip to footer

Are Html Helpers Worth Using With Complex Markup?

Should I persist with using HTML helpers, or just use plain HTML? I've been using HTML helpers for a while now and really enjoyed using them. Recently I've started using CSS framew

Solution 1:

I agree that Html tag helper can do as much to obscure meaning as convey it. We all understand Html (designers and developers) so why not use it? Html helpers simply revert us to the days of Asp.Net controls which emitted Html for us. As an example, which of these two is clearer?

@Html.ActionLink("About this Website", "About") 

or

<a href='/about'>About this website</a> 

Granted the second answer may have more characters, but is far clearer.

Solution 2:

When you have to start doing more advanced things with page elements it starts to get ugly. I always found myself having to go to the rendered page source to see exactly what was generated way to many times. Another issue is when you have a designer trying to style your markup, most will know html but not razor/aspx syntax.

My advice is to do straight html for any site that will utilize a good amount of js libs (jquery/knockout/angular/etc). Especially the form helpers.

Solution 3:

If I'm minimising HTML helper usage, should I just drop them altogether and primarily use regular HTML for consistency?

No, always use HTML helpers. In the example of complex anchors you could still use the Url.Action helper to set its href attribute and hardcode the other parts of it.

Post a Comment for "Are Html Helpers Worth Using With Complex Markup?"