私が正しく理解していれば
ドレス テーブルと顧客テーブル - 1 対多のリレーションシップ
Body テーブルと Customer テーブル - 1 対多の関係
ボディ テーブルとドレス テーブル - 1 対多の関係
もしそうなら、あなたのモデルデザインは以下のようになります。
public class Customer
{
public int CustomerID { get; set; }
public List<Body> parts { get; set; }
public List<Dress> dresses { get; set; }
public Customer()
{
this.parts = new List<Body>();
this.dresses = new List<Dress>();
}
}
public class Body
{
public int PartID { get; set; }
public string DefaultValue { get; set; }
public Customer customer { get; set; }
public Dress dress { get; set; }
}
public class Dress
{
public int DressID { get; set; }
public int PartID { get; set; }
public string LOV { get; set; }
public Customer customer { get; set; }
public List<Body> parts { get; set; }
public Dress()
{
this.parts = new List<Body>();
}
}
ドレス モデルのビューの実装例を作成します。
コントローラ:
public ActionResult Create()
{
List<Body> bodies = new List<Body>()
{
new Body{PartID=1,DefaultValue="Default1"},
new Body {PartID=2,DefaultValue="Default2"},
new Body {PartID=3,DefaultValue="Default3"}
};
Dress dress = new Dress();
dress.parts = bodies;
return View(dress);
}
意見:
@model Mvc4Test.Models.Dress
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Dress</legend>
<div class="editor-label">
@Html.LabelFor(model => model.PartID)
</div>
<div class="editor-field">
@Html.DropDownListFor(x => x.parts, new SelectList(Model.parts,"PartID","DefaultValue"))
@Html.ValidationMessageFor(model => model.PartID)
</div>
<br /><br />
<div class="editor-label">
@Html.LabelFor(model => model.LOV)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.LOV)
@Html.ValidationMessageFor(model => model.LOV)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}