在 ASP.NET-MVC 和 Linq2Sql 的 jQuery 弹出窗口中创建/编辑/保存数据 [英] Create/Edit/Save data in a jQuery pop-up for ASP.NET-MVC and Linq2Sql
问题描述
我有一个 MVC 页面,它允许创建和编辑分包合同.当用户必须为分包选择一家公司时,我希望他们可以选择创建一家新公司.我用公司字段制作了一个 jQuery 弹出窗口,但我不知道如何将这些信息保存到公司表中.我还希望能够使用相同的弹出窗口来允许用户编辑现有公司的信息,但需要指导如何将信息发送到弹出窗口.
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.
推荐答案
使用 AJAX 将数据从弹出窗口(实际上是 jQuery 对话框)中的表单发送回服务器,并在需要时填充对话框进行编辑.
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');
}
},
...
}
});
});
这篇关于在 ASP.NET-MVC 和 Linq2Sql 的 jQuery 弹出窗口中创建/编辑/保存数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!