views:

330

answers:

6

Being comfortable with using html, I find it easier to just use regular html in my views, for example, creating a textbox with <input type="text" maxlength="30" name="firstname"> instead of <%= html.textbox("firstname") %>. Or <form method="post" name="myform"> instead of <% html.beginform() { %>.

Is this considered bad practise ? Should I start to force myself using the helpers etc ? Am I going to run into trouble if I keep using regular html ?

Just something I was wondering, as most of the examples and stuff I see online use all the beforementioned helpers and methods...

+3  A: 

I use custom form helpers in PHP for making input fields. For something quick, they are handy, but when you need to do something out of the ordinary on an element (add some events and javascript, embed an inline style, disabling it) the helper function gets in the way. I prefer having the real HTML since that is what it becomes ultimately anyway.

tkotitan
+1  A: 

I use raw HTML all the time for various reasons, and only put a runat="server" attribute on my tags if I need to access them from my classes.

ASP.NET controls are really great but after a while people (or maybe just me) usually find that they are in your way, especially in advanced scenarios or if you are doing some advanced javascript. And we haven't even mentioned viewstate, which can easily take up half a megabyte(!) on a medium-sized page with some data on it. You just have more control over your page with raw HTML.

So this might sound a bit awkward, but after using ASP.NET controls for a while, I've returned to (mostly) raw HTML. This is a bit like using some really good WYSIWYG editor and then realizing that it actually takes more effort to achieve advanced tasks with it than, say for instance, with notepad.

DrJokepu
A: 

Html helpers will help you by dynamically create html for you. If you decide to rename your controller the Html.BeginForm automatically outputs the correct actionurl for you(some overloads are more dynamic than others). If you hardcoded the actionurl you will have to do a lot more code changing of course. This is true for Htmlhelper as well as Webform controls. They are just more dynamic. And in many cases they just save you a lot of repetitive html code, see mvc grid or gridview.

TT
+1  A: 

Writing HTML straight is never bad practice. When comparing the two; writing it yourself you have to write out the HTML as you see fit, when using pre-made functions the functions will generate the HTML for you as they see fit. I'd say that the latter is on the verge of bad practice depending on how much control you have over the elements. Obviously some are fine, but I've found a large portion of these functions just result in code bloat and/or tag soup.

Andrew G. Johnson
A: 

When I first worked on MVC, I tried to use Html Helpers and even create my own helpers. However, when I tried to use JQuery/Ajax on my application, I tend to use more and more raw HTML. I do not think using raw HTML is a bad practice at all. If you want more control on the client side, raw HTML seems to be the easier way for me.

kimsk
+1  A: 

It's a bit of a pragmatic choice really, but the clue is in the name - they aren't called 'helpers' for nothing.

  • If you're doing simple markup, then go ahead and use raw HTML.
  • If you're doing stuff that caould possibly change, due to restructuring of routing rules for example, then use the helper and it will take care of responding to those changes. A good example of this is the 'BeginForm' helper.

Like most things in life, use common sense.

belugabob