views:

891

answers:

2

I'm just starting to play with MVC, and something isn't clicking with me. I understand how to make a simple input form, and use a submit button to post the form set up like this:

<form runat="server" method="post" action="/Home/CreateNew" >

But what happens if you're whole app is inside one form tag, and you want to have multiple input forms? For example, I'm using some AjaxControlToolkit controls on my master page, which requires the entire page to be inside a form tag. If I have two completely different input forms, do I have to funnel them both through the CreateNew controller? How would I tell the form to use a different action for each input form?

+3  A: 

You should not put one form around the whole page. Put your multiple input forms where you need them. You can get rid of the runat = "server" also. You won't need that in MVC.

Much of the Ajax Control Toolkit is just not going to work in MVC, since MVC does not have ViewState. There is a client-only version, which does work to some degree.

My recommendation is to use jQuery instead. This is now supported by Microsoft, and fits much better within the MVC model.

Craig Stuntz
+2  A: 

Craig is right that you probably should not try to get it to work with one form. That is very anti-mvc and anti-html, however, to answer your question you can use javascript to change the form's action on the fly.

liammclennan
Thanks. It's a slow process to break the old web forms habits in favor of MVC, but I'm starting to get what it's all about.
gfrizzle