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?
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.
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?
or
Granted the second answer may have more characters, but is far clearer.
No, always use HTML helpers. In the example of complex anchors you could still use the
Url.Action
helper to set itshref
attribute and hardcode the other parts of it.