Posting same form to different actions depending on button clicked

前端 未结 2 1027
逝去的感伤
逝去的感伤 2021-01-18 11:36

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()

相关标签:
2条回答
  • 2021-01-18 12:08

    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
    });
    
    0 讨论(0)
  • 2021-01-18 12:26

    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
    });
    
    0 讨论(0)
提交回复
热议问题