How to add additional data in my JQUERY submit?

前端 未结 3 1556
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-15 14:26

In my razor view, I\'m using a Html.BeginForm. In it I have two elements where when I set clic, should submit the form but I need to add an additional string pa

3条回答
  •  执笔经年
    2021-01-15 14:49

    You could add a hidden input with the name and value you require in your form. This value will be submitted along with all the other form items.

    
    

    Edit for comment:

    If you give each of your submit buttons the value as an attribute you could grab it in the click handler and then append a hidden field with the value inside the form. Something like:

    $(function(){
       $('#form input[type=submit]').click(function(e) {
           var val = this.getAttribute("data-param");
           $(this).closest('form').append('");
       });
    });
    

    Untested, just a hunch. Hope that the form submit event does not get fired before the button click event. Also you will need to handle the enter event and key press etc.

    Why don't you want to use ajax?

提交回复
热议问题