I am having the hardest time wrapping my head around this. I recently asked this question Create/Edit/Save data in a jQuery pop-up for ASP.NET-MVC and Linq2Sql I'm sure that the response is the right way to go, but I just can't figure out how to write the back-end code to make it work. I originally made my site by following the nerddinner tutorial. I have a subcontracts model and a subcontracts controller. On my subcontract entry page, I'd like for there to be a pop-up/dialog box where the user can enter a new company if the company isn't already in the drop-down list. Do I need to create a new company controller? I wouldn't have a company model b/c the company table is linked to my subcontracts table within the subcontracts dbml.
Can anyone point me to an example somewhere? Or offer any help.
EDIT: When the company/create method is called, all of the fields are null.
Here's the code:
<div id="popupCreateCompany" title="Create a new company">
<p>
<label for="company_name">Company Name:</label><br />
<%= Html.TextBox("company_name") %>
</p>
<p>
<label for="company_desc">Company Description:</label><br />
<%= Html.TextBox("company_desc") %>
</p>
<p>
<label for="address">Address:</label><br />
<%= Html.TextBox("address") %>
</p>
<p>
<label for="city">City:</label><br />
<%= Html.TextBox("city") %>
</p>
<p>
<label for="state">State:</label><br />
<%= Html.TextBox("state") %>
</p>
<p>
<label for="zip">Zip:</label><br />
<%= Html.TextBox("zip") %>
</p>
<p>
<label for="website">Website:</label><br />
<%= Html.TextBox("website") %>
</p>
</div>
jquery code:
$("#create-company").click(function() {
//centerPopup();
//loadPopup();
$('#popupCreateCompany').dialog(
{
modal: true,
buttons:
{
'Add': function() {
var dialog = $(this);
var form = $(this).find('#popupCreateCompany');
$.post('/company/create', $(form).serialize(), function() {
dialog.dialog('destroy');
})
},
'Cancel': function() {
dialog.dialog('destroy');
}
}
});
});
Also, my fields show up as a separate box which is on top of the dialog.