two submit buttons on a form

后端 未结 2 1757
天涯浪人
天涯浪人 2021-01-28 00:18

lets say I have a set of establishments, each establishments know who his father is and a establishment can have many childs. now I created a set of cascading dropdowns for this

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-28 00:36

    Modify the Button like below.

    
    

    Mofify the Form Tag as mentioned below

    @using (Ajax.BeginForm("SelectParent","Ticket", FormMethod.Post, 
                                                              new { id = "myForm" }))
    {
    }
    

    Modify the Div as mentioned below. Add an attribute which will have value corresponding to it's Controller's Action method.

    Now in Jquery. Follow below steps.

    1. Load Partial View
    2. Fetch the Div Attribute Value
    3. Use On for the Button event.
    4. Ajax Request

    JQuery

    $(document).ready(function () {
        var FirstHeritage = $('#FirstHeritage');
        var url = FirstHeritage.attr('attr-Url');
        FirstHeritage.load(url, function () {
            var $form = $('#myForm');
            $.validator.unobtrusive.parse($form);
            $(document).on('click', '.btnSubmit', function () {
                if ($form.valid()) {
                    $.ajax({
                        url: Url,
                        async: true,
                        type: 'POST',
                        beforeSend: function (xhr, opts) {
    
                        },
                        contentType: 'application/json; charset=utf-8',
                        complete: function () { },
                        success: function (data) {
                            $form.html(data);
                            $form.removeData('validator');
                            $form.removeData('unobtrusiveValidation');
                            $.validator.unobtrusive.parse($form);
                        }
                    });
                }
            });
        });
    });
    

    Hope this will help you.

提交回复
热议问题