Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the proper way to handle forms in ASP.NET MVC?

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.

like image 216
KingNestor Avatar asked Oct 27 '25 18:10

KingNestor


1 Answers

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.

like image 156
aleemb Avatar answered Oct 30 '25 13:10

aleemb