我有一个ASP.NET MVC 4项目与EF 我有一个表Parteners。此表有两种类型的parteners:代理(part_type = 1)和客户端(part_type = 2)。 在创建视图中,我有第一个显示所有我的代理的DropDownList,一个按钮和第二个DDL,显示与选定代理对应的所有客户端。 Q1:我用什么按钮? ,@ Html.ActionLink()? Create.cshtmlMVC 4级联DropDown列表
<div class="editor-field">
@Html.DropDownList("idagenti", ViewData["idagenti"] as List<SelectListItem>, String.Empty)
</div>
@*a button*@
<div class="editor-label">
@Html.LabelFor(model => model.id_parten, "Client")
</div>
<div class="editor-field">
@Html.DropDownList("id_parten", String.Empty)
@Html.ValidationMessageFor(model => model.id_parten)
</div>
OrdersController.cs
public ActionResult Create(int? id) // id is the selected agent
{
var agqry = db.partener.Where(p => p.part_type == 1).Where(p => p.activ == true);
var cltqry = db.partener.Where(p => p.part_type == 2).Where(p => p.activ == true);
List<SelectListItem> idagenti = new List<SelectListItem>();
foreach (partener ag in agqry)
{
idagenti.Add(new SelectListItem { Text = ag.den_parten, Value = ag.id_parten.ToString() });
}
if (id != null)
{
cltqry = cltqry.Where(p => p.par_parten == id);
}
ViewData["idagenti"] = idagenti;
ViewBag.id_parten = new SelectList(cltqry, "id_parten", "den_parten");//
}
问:如何传递从第一DDL选定代理人身份证到我的控制器?
http://blogs.msdn.com/b/rickandy/archive/2012/01/09 /cascasding-dropdownlist-in-asp-net-mvc.aspx – RickAndMSFT
可能的重复:http://stackoverflow.com/questions/705540/asp-net-mvc-cascading-drop-down –
[与jQuery MVC AJAX级联DropDown列表](HTTP:// lesson8 .blogspot.com/2013/07/cascading-dropdown-lists-with-jquery.html) – Sender