Create/Edit/Save data in a jQuery pop-up for ASP.N

2020-05-24 18:02发布

I have a MVC page which allows creation and editing of a subcontract. When the user has to select a company for the subcontract, I would like for them to have the option to create a new company. I've made a jQuery pop-up with the company fields, but I don't know how to then save this information to the company table. I would also like to be able to use the same pop-up to allow the user to edit the information for an existing company, but need direction in how to send the information to the pop-up.

2条回答
Bombasti
2楼-- · 2020-05-24 18:13

Use AJAX to both send the data from a form in the pop-up (jQuery dialog, really) back to the server and to populate the dialog when you want to do the editing.

$('#addSubcontract').click( function() {
    $.get('/company/new', null, function(data) {
        $('<div>' + data + '</div>').dialog({
            modal: true,
            buttons: {
               'Add': function() {
                        var dialog = $(this);
                        var form = $(this).find('form');
                        $.post('/company/new', $(form).serialize(), function() {
                            dialog.dialog('destroy');
                        }
                      }
               'Cancel': function() {
                      $(this).dialog('destroy');
                      }
           },
           ...
       }
    });
});
查看更多
爱情/是我丢掉的垃圾
3楼-- · 2020-05-24 18:36

I was looking for a solution to this question today.

Found a really nice opensource solution with demo. I figure I'll link it here to save others' time. It's call jQuery Inline Edit.

http://www.codenothing.com/archives/jquery/inline-text-edit/

查看更多
登录 后发表回答