Ich habe drei Tabellen in meiner Datenbank wie folgt:ASP.NET MVC Cascading Drop-Down-
University
id Name
1 A
2 B
Faculty
id id_uni name
1 1 AA
2 1 AA
cafedry
id id_uni id_faculty name
1 1 1 cc
Ich möchte ein Cascading Drop-Down schaffen, die mir erlauben, zuerst eine Universität wählen dann eine Fakultät, gefolgt von einem Cafedry . Unten Code ist was ich bisher versucht habe.
public ActionResult Create()
{
ViewBag.fak_kod = new SelectList(db.Fakulteler, "id", "adi");
ViewBag.unikod = new SelectList(db.Universitetler, "id", "adi");
return View();
}
// POST: kafedras/Create
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "id,unikod,fak_kod,adi")] kafedra kafedra)
{
if (ModelState.IsValid)
{
db.kafedra.Add(kafedra);
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.fak_kod = new SelectList(db.Fakulteler , "id", "adi", kafedra.fak_kod);
ViewBag.unikod = new SelectList(db.Universitetler, "id", "adi", kafedra.unikod);
return View(kafedra);
}
und diese cshtml
<div class="form-horizontal">
<h4>kafedra</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.unikod, "unikod", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("unikod", null, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.unikod, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.fak_kod, "fak_kod", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("fak_kod", null, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.fak_kod, "", new { @class = "text-danger" })
</div>
</div>
Wie dieser Code aktualisieren kann einen Cascading Drop-Down mit den drei Tabellen zu erstellen?
So möchten Sie Cascading Drop-Down implementieren? – Shyju
ja eigentlich geben Sie mir manuell in Dropwdown auswählen bu ich möchte Cascading zum Beispiel wählen Sie die Universität AA dann in der Fakultät dropdwon zeigen, welche Fakultät haben eine in der Universität –
Werfen Sie einen Blick auf diese https://stackoverflow.com/questions/46954959/how-to -create-cascading-drop-down-list – Shyju