我有一個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