在 jquery 对话框和帖子之后添加新选项到下拉列表
我有一份用于签订分包合同的表格。在这张表格上,我有系统中所有公司的下拉列表。旁边是一个“创建公司”按钮。此按钮将打开一个 jquery 对话框,允许用户创建新公司。对话框关闭后,需要将新公司添加到下拉列表中并进行选择。如果我刷新,它就在那里,但我需要在不刷新表单的情况下执行此操作 b/c 我不希望用户丢失他们在其他字段中输入的所有内容。我不知道如何执行此操作,因为我没有新公司的 guid/company_id。
我的 jquery 对话框:
$('#popupCreateCompany').dialog(
{
autoOpen: false,
modal: true,
buttons:
{
'Add': function() {
var dialog = $(this);
var form = dialog.find('input:text, select');
$.post('/company/create', $(form).serialize(), function() {
dialog.dialog('close');
})
},
'Cancel': function() {
$(this).dialog('close');
}
}
});
$("#create-company").click(function() {
$('#popupCreateCompany').dialog('open');
});
公司字段:
<label for="company">Company:</label>
<%= Html.DropDownList("company", Model.SelectCompanies, "** Select Company **") %>
<%= Html.ValidationMessage("Company", "*") %>
<button type="button" id="create-company" >Create Company</button>
SelectList 声明:
SelectCompanies = new SelectList(subcontractRepository.GetPrimaryCompanies(), "company_id", "company_name", Subcontract.company);
I have a form to enter subcontracts. On this form I have a dropdownlist of all companies in the system. Next to it is a button "Create Company". This button opens a jquery dialog which allows the user to create a new company. Once the dialog closes, the new company needs to be added to the dropdownlist and selected. If I refresh, it's there, but I need to do it without refreshing the form b/c I don't want the user to loose everything that they've entered into the other fields. I'm not sure how to do this b/c I don't have the guid/company_id of the new company.
My jquery dialog:
$('#popupCreateCompany').dialog(
{
autoOpen: false,
modal: true,
buttons:
{
'Add': function() {
var dialog = $(this);
var form = dialog.find('input:text, select');
$.post('/company/create', $(form).serialize(), function() {
dialog.dialog('close');
})
},
'Cancel': function() {
$(this).dialog('close');
}
}
});
$("#create-company").click(function() {
$('#popupCreateCompany').dialog('open');
});
Company field:
<label for="company">Company:</label>
<%= Html.DropDownList("company", Model.SelectCompanies, "** Select Company **") %>
<%= Html.ValidationMessage("Company", "*") %>
<button type="button" id="create-company" >Create Company</button>
SelectList declaration:
SelectCompanies = new SelectList(subcontractRepository.GetPrimaryCompanies(), "company_id", "company_name", Subcontract.company);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我得到了它。我随指南返回了一个 Json。
I got it. I returned a Json with the guid.