It will seem a little stupid thing, but that is what I want to know nonetheless.
Right now, in ASP.NET MVC 3.0, you need to use the @using (Html.BeginForm()) { and then } syntax to close the form block to get a fantastic new “unobtrusive javascript” so you don't write all this manually (this is good).
For some reason ( Read: *OCD* ) I don't like this. I would rather do it.
@Html.BeginForm() <div class="happy-css"> </div> @Html.EndForm()
Seems still stupid? Yes, it’s good for everyone. I want to understand why it works the way it is, and shape it to your liking. So I thought that the first place I will start digging is the source of MVC 3.0. So I went into codeplex to find the BeginForm Extension method.
( http://aspnet.codeplex.com/SourceControl/changeset/view/63452#288009 )
So, now I'm a little confused about how to start achieving my goal. After reading the code, I found that they all go to the root method (not surprising, since most extension methods seem to be hierarchical methods, all of which boil down to one, to avoid redundancy).
private static MvcForm FormHelper(this HtmlHelper htmlHelper, string formAction, FormMethod method, IDictionary<string, object> htmlAttributes) { TagBuilder tagBuilder = new TagBuilder("form"); tagBuilder.MergeAttributes(htmlAttributes);
I do not see here how this method relates to unobtrusive javascript. If I just type ..
<form action="/Controller/Action" method="post">
and then enter my check this way ...
@Html.ValidationSummary(false)
I do not get unobtrusive javascript. But if I use
@using (Html.BeginForm()) { , then I do it. I even studied the generated markup, and I really can't find the difference.
Now it is getting weird. If I just type ...
@Html.BeginForm() and then put all my form code, the form works , and I get unobtrusive javascript, but I need to manually enter </form> at the end. @Html.EndForm() does not work. But now, I now get the text System.Web.Mvc.Html.MvcForm written to the output stream directly under the <form action="/Controller/Action" method="post"> html.
Can someone enlighten and / or help me?