Thursday, April 24, 2008 9:29 AM
Part of my UG talk the other night involved going over the helper classes that come with the MVC framework. These make it pretty easy to generate HTML that is friendly to your MVC structure without having to hand-bomb the markup yourself. You can read a great article covering them on Rob Conery's blog here.
One of these helpers is Html.Form. This outputs a form tag with the appropriate href for handling any submit action that occurs. In the code below, you can see that I've got three helpers: the form, a textbox, and a submit button. By specifying the controller and action in the form helper, I don't have to specify anything else in the Submit button other than a name...kewl.
Now here's the weird behavior. If you code the above, your page renders like this:

Not really what we were expecting. In fact if you look at the source...
There's no actual closing tag for the Form element. Obviously we need to alter this. You could try putting in the ending form tag...
But the output is identical to the above except you have a closing form tag...the opening tag is still left open.
One of the guys in attendance, Orion (awesome name btw), offered a solution that I *never* would have thought of...the 'Using' statement...
This outputs our screen properly without that 'System.Web.Mvc.SimpleForm' showing up...
And if we look at the source, we see that its actually rendering properly...
So for whatever reason, the using tells it to kick out the end tag as well as close the start tag properly. I'm not sure where else this is applicable with the helpers, but I'm sure we'll see some other situations where this would be applicable.
D