Skip to content Skip to sidebar Skip to footer

Posting Same Form To Different Actions Depending On Button Clicked

I have a similar post on this on StackOverflow but perhaps my misunderstanding is more substantial. I have an action Index() and an Index view its rendering. From Index() view de

Solution 1:

You can change the form's action attribute depending on which button was clicked.

e.g. To post to the 'search' action when the 'go' button is clicked:

$('#go_button').click(function() {
    $('form').attr("action", "Search");  //change the form action
    $('form').submit();  // submit the form
});

Solution 2:

Additional to accepted answer when you are in need to change action as well as Controller too:

$('#go_button').click(function() {
    $('form').attr("action", "@("Search","OtherControllerName")");  //change the form action
    $('form').submit();  // submit the form
});

Post a Comment for "Posting Same Form To Different Actions Depending On Button Clicked"