I am new to asp. I have to write an application in mvc that has a database where I have two tables. One Parent table is used for many with the Kids table.
Parent ------------- parent_id name Children ------------- children_id parent_id (foreign key) name
When the user wants to create an element for the parent table, the editor should be able to add (create) children.
When a user edits Parent, he should be able to delete / edit Children.
Unable to add / edit / delete children in separtet editor
I think sholuld used javascript to create additional controls for Child. I can do this, but I don’t know how to map these html controls for simulation?
I wrote this opinion:
<script language="javascript" type="text/javascript"> function add_child() { $('#children').append($('<input name="child[' + ++$('#children>input').get().length + ']" />')); } </script> @using (Html.BeginForm()) { @Html.ValidationSummary(true) <fieldset> <legend>Create Parent</legend> <div class="editor-label"> @Html.LabelFor(model => model.Name) </div> <div class="editor-field"> @Html.EditorFor(model => model.Name) @Html.ValidationMessageFor(model => model.Name) </div> <div>Children:</div> <div id="children"> @Html.TextBox("child[1]") </div> <div> <input onclick="add_child()" type="button" /> </div> <p> <input type="submit" value="Create" /> </p> </fieldset> }
It works great. But I do not know how to display this element on my parent model.
Now my model for creating is as follows:
public class ParentModel { public ParentModel() { Children =
How to populate these children with values from the view?
Controller:
public class ParentController : Controller {
I want to read form.CreatedChildren, but it's Null ...
source share