views:

231

answers:

2

Forms + ASP.NET MVC = Confusing for me:

  1. What are the preferred ways to setup your controller action for form posts?

    • Do I need to specify an attribute that has [AcceptVerbs(HttpVerbs.Post)]?
    • Should the controller action take a "FormCollection" or should I use ModelBinders?
    • If I should use ModelBinders, how?
  2. How do I setup the form in the view?

    • Should I use the Html helpers like Html.BeginForm/Html.EndForm or simply specify the form tag myself?
    • How do you specify the controller and action to be used in a form (with either the Html helpers or with a manual form tag)?

Can somebody please show me both a simple view with a form ~and~ its corresponding controller action?

I'm trying to write a form with a single textbox that I can submit to the Home/Create action and pass the string from the textbox to it.

A: 

The template's AccountController.LogOn and .Register methods along with the corresponding views should give you the simple introduction you need.

royatl
+4  A: 

ScottGu's handling form edit and post scenarios is exactly what you're looking for. There's also form posting scenarios and even though it was written for preview 5, it's still mostly valid.

aleemb