Search code examples
asp.net-mvcasp.net-mvc-4html-helper

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 frameworks such as Twitter Bootstrap and I'm finding that my markup is too complex to use the standard HTML helpers.

Of course, I still use Url.Action() for generating links and sometimes @Html.TextBoxFor() or similar for simple forms, but, for example, I'm finding some helpers like Html.ActionLink() or Using Html.BeginForm() just don't cut it.

My markup often contains complex nests. For example, in Bootstrap I might want to add an icon as part of a link:

<a href="#">
    <i class="icon-user"></i>
    <span>Simple link</span>
</a>

This is very common with Bootstrap and I feel like HTML helpers would get in the way. I can make my own, but my markup is quite different all over.

Suppose I only use HTML helpers in small amounts; where needed. This raises another question:

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


Solution

  • 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.