Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC submit form to different controllers

Is it possible to post the same form to different controllers?

Each page could be post only to form action url, but may be some how i may say to button to which url form should go?

e.g i have one form and two submit buttons, one button will post form to one controller/url (eg /action/view) anther button submit form to one to another controller/url (eg /action/anothervew).

like image 759
Juk Avatar asked Aug 13 '10 13:08

Juk


1 Answers

You can definitely do this, use JQuery (or just javascript) to attach a function to the onclick event of the button(s). Then use that function to change the URL that the form posts to and then submit the form.

JQuery would be something like:

$('#button1').onclick(function(){ $(this).action = url1; $(document).submit();});
$('#button2').onclick(function(){ $(this).action = url2; $(document).submit();});
like image 109
Paul Hadfield Avatar answered Oct 20 '22 07:10

Paul Hadfield