MVC razor form with multiple different submit buttons?

前端 未结 13 1967
-上瘾入骨i
-上瘾入骨i 2020-12-04 12:59

A Razor view has 3 buttons inside a form. All button\'s actions will need form values which are basically values coming input fields.

Every time I click any of butto

13条回答
  •  暖寄归人
    2020-12-04 13:49

    You can use JS + Ajax. For example, if you have any button you can say it what it must do on click event. Here the code:

     
    

    Here your button in html: in the script section, you need to use this code (This section should be at the end of the document):

    
    

    And finally, you need to add ajax function (In another script section, which should be placed at the begining of the document):

    function myFunc() {
        $.ajax({
            type: "GET",
            contentType: "application/json",
            url: "/myController/myFuncOnController",
            data: {
                 //params, which you can pass to yu func
            },
            success: function(result) {
    
            error: function (errorData) {
    
            }
        });
    };
    

提交回复
热议问题