为了注册一个新客户,我的视图中有几个部分,它们引用了我数据库中的相应表。主键是身份字段,这就是视图上没有 ID 的原因。要插入一个新客户,我需要插入 3 个地址(访问、邮政和联系人),然后插入一行合同,contact_person(使用来自已插入地址之一的 addressId),最后继续插入一个新客户将包含引用刚刚插入的访问地址和邮政地址、合同和联系人的外键。
您能否推荐将这些部分视图中的数据作为对象传递给 CustomerController 并处理那里的对象的最佳/最简单方法?处理类似情况的示例的链接也将受到高度赞赏。
我的页面图片:http: //i1345.photobucket.com/albums/p673/swell_daze/customer_registration_zps563341d0.png
表格图片:http: //i1345.photobucket.com/albums/p673/swell_daze/tables_zpsc60b644a.png
查看代码:
@model CIM.Models.customer
<h2>Register new customer</h2>
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<fieldset>
<legend>New customer registration</legend>
<fieldset class="span3">
<legend>Basic information</legend>
<div class="editor-label">
@Html.LabelFor(model => model.name, "Name")
</div>
<div class="editor-field">
@Html.EditorFor(model => model.name)
@Html.ValidationMessageFor(model => model.name)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.groupId, "Customer group")
</div>
<div class="editor-field">
@Html.DropDownList("groupId", String.Empty)
@Html.ValidationMessageFor(model => model.groupId)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.status, "Status")
</div>
<div class="editor-field">
@Html.DropDownList("status")
@Html.ValidationMessageFor(model => model.status)
</div>
</fieldset>
<fieldset class="span3">
<legend>Visiting address</legend>
<div>
@{
Html.RenderPartial("AddressPartial");
}
</div>
</fieldset>
<fieldset style="width:270px">
<legend>Postal address</legend>
<div>
@{
Html.RenderPartial("AddressPartial");
}
</div>
</fieldset>
<fieldset class="span3">
<legend>Contract</legend>
<div>
@{
Html.RenderPartial("ContractPartial");
}
</div>
</fieldset>
<fieldset class="span3" style="width:540px">
<legend>Contact person</legend>
<div>
@{
Html.RenderPartial("ContactPersonPartial");
}
</div>
<p>
<input type="submit" class="btn btn-success" value="Submit" style="margin-right:1em"/>
@Html.ActionLink("Cancel", "Index", "Customer", new {@class="btn btn-danger", @type="button"})
</p>
</fieldset>
</fieldset>
}