Selected value from drop-down list doesn't post from jquery dialog
Posted
by RememberME
on Stack Overflow
See other posts from Stack Overflow
or by RememberME
Published on 2010-04-19T15:10:45Z
Indexed on
2010/04/19
15:13 UTC
Read the original article
Hit count: 420
I have a jQuery dialog. All of the fields are posting correctly except for the drop-downs, the value is getting passed as null rather than the selected value.
<div id="popupCreateCompany" title="Create a new company">
<form>
<fieldset>
<p>
<label for="company_name">Company Name:</label>
<%= Html.TextBox("company_name") %>
</p>
<p>
<label for="company_desc">Company Description:</label>
<%= Html.TextBox("company_desc") %>
</p>
<p>
<label for="address">Address:</label>
<%= Html.TextBox("address") %>
</p>
<p>
<label for="city">City:</label>
<%= Html.TextBox("city") %>
</p>
<p>
<label for="state">State:</label>
<%= Html.TextBox("state") %>
</p>
<p>
<label for="zip">Zip:</label>
<%= Html.TextBox("zip") %>
</p>
<p>
<label for="website">Website:</label>
<%= Html.TextBox("website", "http:/") %>
</p>
<p>
<label for="sales_contact">Sales Contact:</label>
<%= Html.DropDownList("sales_contact", Model.SelectSalesContacts, "** Select Sales Contact **") %>
</p>
<p>
<label for="primary_company">Primary Company:</label>
<%= Html.DropDownList("primary_company", Model.SelectPrimaryCompanies, "** Select Primary Company **") %>
</p>
</fieldset>
</form>
jQuery:
$('#popupCreateCompany').dialog(
{
autoOpen: false,
modal: true,
buttons:
{
'Add': function() {
var dialog = $(this);
var form = dialog.find('input:text');
$.post('/company/create', $(form).serialize(), function() {
dialog.dialog('close');
})
},
'Cancel': function() {
$(this).dialog('close');
}
}
});
$("#create-company").click(function() {
$('#popupCreateCompany').dialog('open');
});
My SelectList definitions:
public class SubcontractFormViewModel
{
public subcontract Subcontract { get; private set; }
public SelectList SelectPrimaryCompanies { get; set; }
public MultiSelectList SelectService_Lines { get; private set; }
public SelectList SelectSalesContacts { get; private set; }
public SubcontractFormViewModel(subcontract subcontract)
{
SubcontractRepository subcontractRepository = new SubcontractRepository();
Subcontract = subcontract;
SelectPrimaryCompanies = new SelectList(subcontractRepository.GetPrimaryCompanies(), "company_id", "company_name");
SelectService_Lines = new MultiSelectList(subcontractRepository.GetService_Lines(), "service_line_id", "service_line_name", subcontractRepository.GetSubcontractService_Lines(Subcontract.subcontract_id));
SelectSalesContacts = new SelectList(subcontractRepository.GetContacts(), "contact_id", "contact_name");
}
}
© Stack Overflow or respective owner