Reputation: 73
I'm using EF code first, my models look like this:
public class Warehouse
{
public int Id { get; set; }
public ICollection<Item> Items { get; set; }
public ICollection<Branch> Branches { get; set; }
}
Apparently the scaffolded view doesn't support such scenarios; how can I add Items
and Branches
in Warehouse/Create page? Here is the scaffolded View:
@model WarehouseManagementMVC.Models.Warehouse
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Warehouse</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
Upvotes: 0
Views: 58
Reputation: 50728
You have to understand how posting collections work; please see this SO post on how that can be done: How can I post a list of items in MVC
I would caution though against posting the collections back directly to the EF object; the reason being is that you have to make sure EF may interpret inserts or updates correctly, and if it doesn't have all of the respective info, it may not make the right decision. Plus, any metadata properties also need to be included in the UI if you are updating, and if that doesn't come back properly, it could have negative consequences.
Upvotes: 1