How do you handle multiple submit buttons in ASP.NET MVC Framework?

后端 未结 30 2989
一个人的身影
一个人的身影 2020-11-21 07:16

Is there some easy way to handle multiple submit buttons from the same form? For example:

<% Html.BeginForm(\"MyAction\", \"MyController\", FormMethod.Pos         


        
30条回答
  •  我在风中等你
    2020-11-21 07:28

    This script allows to specify a data-form-action attribute which will work as the HTML5 formaction attribute in all browsers (in an unobtrusive way):

    $(document).on('click', '[type="submit"][data-form-action]', function(event) {
        var $this = $(this),
        var formAction = $this.attr('data-form-action'),
        $form = $($this.closest('form'));
        $form.attr('action', formAction);             
    });
    

    The form containing the button will be posted to the URL specified in the data-form-action attribute:

       
    

    This requires jQuery 1.7. For previous versions you should use live() instead of on().

提交回复
热议问题