1
我不明白爲什麼我的編輯頁面無法在我的下拉列表中獲取選定的值。Asp.net MVC5 Bootstrap:無法在編輯頁面中獲取選定的值Dropdownlist
我的創建功能工作正常,但我的編輯頁面不在我的下拉列表中顯示選定的值。我試圖通過使用Viewbags獲取選定的值,如果我正在調試,ID的存在。
這是我Edit()
public ActionResult Edit(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
SeminarErstellen seminarerstellen = db.SeminarErstellen.Find(id);
if (seminarerstellen == null)
{
return HttpNotFound();
}
ViewBag.FileUploadId = new SelectList(db.FileUpload, "FileUploadId", "FilePath", seminarerstellen.FileUploadId);
ViewBag.LehrbeauftragterId = new SelectList(db.Lehrbeauftragter, "LehrbeauftragterId", "Vorname", seminarerstellen.LehrbeauftragterId);
ViewBag.SeminarStatiId = new SelectList(db.SeminarStati, "SeminarStatiId", "StatusTyp", seminarerstellen.SeminarStatiId);
ViewBag.SeminarTypId = new SelectList(db.SeminarTyp, "SeminarTypId", "Seminarbezeichnung", seminarerstellen.SeminarTypId);
return View(seminarerstellen);
}
這是我查看下拉列表:問題是,它總是選擇我的下拉列表的第一個項目,而不是選擇一個...我希望你能理解。 ..
<div class="form-group">
@Html.LabelFor(model => model.SeminarTypId, "SeminarTypId", new { @class = "control-label col-md-2" })
<div class="col-md-3">
@* This Dropdown is selecting the right value but without Bootstrap!*@
@*@Html.DropDownList("SeminarTypId", String.Empty)*@
@* This line is selecting the wrong item, its selecting the first item of the list*@
@Html.DropDownList("SeminarTypId", (SelectList)ViewBag.SeminarTypId, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.SeminarTypId)
</div>
</div>
嘿ShekharPankaj, – Armando82
非常感謝你...是其工作的罰款... – Armando82
然後標記問題的解決 –