tags:

views:

232

answers:

6

Which way do you prefer to create your forms in MVC?

<% Html.Form() { %>
<% } %>

Or

<form action="<%= Url.Action("ManageImage", "UserAccount") %>" method="post">
</form>

I understand that Html.Form() as of PR5 now just uses the URL provided by the request. However something about that doesn't sit well with me, especially since I will be getting all the baggage of any querystrings that are included.

What is your take?

+3  A: 

On the whole, I think I'm kinda old-school as I prefer to roll my own HTML elements.

I also prefer a view engine like like NHaml, which makes writing HTML almost an order of magnitude simpler.

Brad Wilson
+6  A: 

The second way, definitely. The first way is programmer-centric, which is not what the V part of MVC is about. The second way is more designer centric, only binding to the model where it is necessary, leaving the HTML as natural as possible.

Will
I find myself doing it the first way, mostly. I'm a hypocrite.
Will
+1  A: 

I have to agree with both of you, I am not really like this simplistic WebForms style that seems to be integrating its way in to MVC. This stuff almost seems like it should be a 3rd party library or at the very least an extensions library that can be included if needed or wanted.

Nick Berardi
+1  A: 

I am totally in the opinion of old school HTML, that is what designers use. I don't like to include to much code centric syntax for this reason. I treat the web form view engine like a third party library, because I replaced it with a different view engine. If you do not like the way the web form view model works or the direction it is going, you can always go a different route. That is one of the main reasons I love ASP.NET MVC.

Dale Ragan
A: 

The reason for using helpers is that they allow you to encapsulate common patterns in a consistent and DRY fashion. Think of them as a way of refactoring views to remove duplication just as you would with regular code.

For example, I blogged about some RESTful NHaml helpers that can build urls based on a model.

Andrew Peters
+1  A: 

I agree with Andrew Peters, DRY. It should also be pointed out that you can specify your controller, action, and params to the .Form() helper and if they fit into your routing rules then no query string parameters will be used.

I also understand what Will was saying about the V in MVC. In my opinion I do not think it is a problem to put code in the view as long as it is for the view. It is really easy to cross the line between controller and view if you are not careful. Personally I can not stand to use C# as a template engine without my eyes bleeding or getting the urge to murder someone. This helps me keep my logic separated, controller logic in C#, view logic in brail.

Andrew Burns