【发布时间】:2016-03-23 23:47:30
【问题描述】:
我一直在尝试剖析自动化 MVC 视图和控制器,并对其进行修改,以便我可以将视图中的表单中的信息插入到两个单独的数据库表中(首先是实体框架数据库)。
这是我到目前为止所拥有的。如果我自己引用顶部的任何一个命名空间,但不是一起引用,它会起作用吗?
@model manage.mysite.DataModels.Property_Type
@model manage.mysite.DataModels.Room_Type
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
@using (Html.BeginForm())
{
<div class="form-horizontal">
<h4>Property_Type</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.PropertyType, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.PropertyType, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.PropertyType, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.RoomType, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.RoomType, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.RoomType, "", new { @class = "text-danger" })
</div>
</div>
<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>
}
【问题讨论】:
标签: asp.net-mvc entity-framework model-view-controller razor