I’ve got a simple structure
Widget (parent table)
-
id (IDENTITY)
-
title
WidgetChild (child table) –
- id (foreign key to widget.id)
- content
On my View i have one field that captures the title, and another field that captures the content value.
<%= Html.TextBox('title') %>
and
<%= Html.TextBox('content') %>
How do i go about wiring up my controller to insert a new entry into Widget first and then insert an entry into WidgetChild? I’m not sure how to go about doing this.. do I pass a FormCollection instance, manually instantiate the Widget instance and pass in the values? Or can i use UpdateModel() somehow? I’m not familiar with how UpdateModel could bind my form values especially if they span multiple tables/classes.
You could use automatic model binding here.
With a form like this:
Your controller can then look like this:
The objects will have the properties from the form populated there (Title for widget, and Content for childWidget) – then you can associate these objects with each other and save them to your linq to sql data context in the normal way.