如果我理解正确
梳妆台和客户表 - 一对多关系
正文表和客户表 - 一对多关系
Body table 和 Dress table - 一对多关系
如果是这样,您的模型设计将如下所示。
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")
}