I would like to know how can I create parent object with its child collection in one step using ADO.net Entity Data Model.
Example: This is the parent object "Video" and its Child VideoData Diagram
I need to create video object with Video data
this is the razor view created by scaffolding options
@model Test.Models.Video
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Video</legend>
<div class="editor-label">
@Html.LabelFor(model => model.AddedDate)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.AddedDate)
@Html.ValidationMessageFor(model => model.AddedDate)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Data)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Data)
@Html.ValidationMessageFor(model => model.Data)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.IsYouTube)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.IsYouTube)
@Html.ValidationMessageFor(model => model.IsYouTube)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.ImageUrl)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ImageUrl)
@Html.ValidationMessageFor(model => model.ImageUrl)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.IsApproved)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.IsApproved)
@Html.ValidationMessageFor(model => model.IsApproved)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.ApprovedBy)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ApprovedBy)
@Html.ValidationMessageFor(model => model.ApprovedBy)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.LastModifiedDate)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.LastModifiedDate)
@Html.ValidationMessageFor(model => model.LastModifiedDate)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
as you can notice, the razor view does not contain any fields associated with the related video data entity.
my question is: How can I add videoData to video creation process.
if it may help, here is the HttpPost
Create in the VideoController
[HttpPost]
public ActionResult Create(Video video)
{
if (ModelState.IsValid)
{
db.Videos.AddObject(video);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(video);
}
I need the posted video object to contain its associated VideoData collection
Please advice