我是编程实体框架 MS 的初学者
对于我设法“建模”和“控制器”并列出、创建和删除的客户实体,我有两个实体“档案”和“客户”。我想对“文件夹”做同样的事情,因为知道每个文件都属于“客户”关系:(dosiers.dos_CL_N = clienst.CL_N)我发现在页面文件创建中很难使用“DropDownList”提前感谢您的帮助这是我的 asp 代码 Create.aspx
<% using (Html.BeginForm()) {%>
<%: Html.ValidationSummary(true) %>
<fieldset>
<legend>Fields</legend>
<div class="editor-label">
<%: Html.LabelFor(model => model.DOS_N) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.DOS_N) %>
<%: Html.ValidationMessageFor(model => model.DOS_N) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.DOS_CL_N) %>
</div>
<div class="editor-field">
<asp:DropDownList ID="ClientDropDownList" runat="server"
DataSourceID="ClientDataSource" DataTextField="CL_NOM" DataValueField="CL_N"
AppendDataBoundItems="True">
</asp:DropDownList>
<asp:EntityDataSource ID="ClientDataSource" runat="server"
ConnectionString="name=ClientsManagerDBEntities"
DefaultContainerName="ClientsManagerDBEntities" EnableFlattening="False"
EntitySetName="Clients" EntityTypeFilter="Clients"
Select="it.[CL_N], it.[CL_NOM]">
</asp:EntityDataSource>
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
<% } %>
<div>
<%: Html.ActionLink("Back to List", "DossiersList")%>
</div>
档案控制器.cs
....
...
// GET: /DossiersManager/Dossier/Create
public ActionResult Create()
{
return View();
}
//
// POST: /DossiersManager/Contact/Create
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create([Bind(Exclude = "Id")] Dossiers DossierToCreate)
{
if (!ModelState.IsValid)
return View();
try
{
_entities.AddToDossiers(DossierToCreate);
_entities.SaveChanges();
return RedirectToAction("DossiersList");
}
catch
{
return View();
}
}
...
..