내가 거기에 있었다 알고 anumberofquestionsaskedsimilar에 그러나 이것들은 모두 POST를 시도 할 때 잘로드되고 문제가있는 페이지를 다루는 것처럼 보입니다. 코드 첫 번째 데이터베이스와 함께 MVC 프로젝트에서 스캐 폴딩 된 코드를 사용하고 있습니다. 실패한 드롭 다운은 외래 키 관계로 채워 져야한다고 가정합니다. 똑같은 코드를 사용하지만 이름이 다른 두 개의 드롭 다운이 있으며,이 드롭 다운이 잘못되었음을 보여주는 주석이 있습니다. 이것은 편집해야하지만 다른 질문처럼 데이터를 제출하기 위해 페이지가로드되지 않습니다. 작성 및 편집 페이지가로드되지 않습니다. 말했다 모두와 함께 비계 모델 /보기 : '선택 System.String'키 'COLUMN'유형 인을 가지고 있지만 형식이어야해야을 ViewData 항목 '을 IEnumerable <SelectListItem>'
, 이것은 컨트롤러 :public ActionResult Edit(long? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Person person = db.People.Find(id);
if (person == null)
{
return HttpNotFound();
}
ViewBag.Title = new SelectList(db.Job_Title, "Id", "Title", person.Title);
ViewBag.Location = new SelectList(db.Locations, "Id", "Name", person.Location);
ViewBag.Manager = new SelectList(db.Managers, "Id", "Name", person.Manager);
return View(person);
}
이 해당보기의 섹션 :
<div class="form-group">
@Html.LabelFor(model => model.Title, "Title", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@*FIXME: Commenting the line below will allow the page to load fine*@
@Html.DropDownList("Title", null, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Title, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Location, "Location", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("Location", null, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Location, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Manager, "Manager", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("Manager", null, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Manager, "", new { @class = "text-danger" })
</div>
</div>
난 그냥 제목 드롭 다운을 죽이는 이유를 알고 싶어요 페이지 2는 완전히 괜찮습니다. 또한 스캐 폴드 코드가 오류와 함께 생성 된 이유를 알고 싶습니다!
좋은 캐치! viewbag 항목 이름을'ViewBag.TitleList'로 변경하고이를 사용하도록 UI 코드를 업데이트 할 수 있습니다. '@Html.DropDownList ("Title", SelectBag.TitleList as SelectList)'또는 더 좋은 속성 이름을 가진 뷰 모델을 사용하는 것이 더 정확합니다 – Shyju
@Shyju, '제목 '은 이미 설정되어 있습니다 (올바른 옵션이 아닌 첫 번째 옵션이 항상 선택됩니다). 항상 그렇듯이 뷰 모델을 사용하고 속성 이름을 변경하여 Salutation을 말하십시오. –
@StephenMuecke 좋아요, 그래서 파일의 맨 위에있는 행을 봅니다. 그러나 제안 된 해결책이 무엇인지 혼란스러워합니다. . 이것이 스캐 폴딩 된 이후로 뷰 모델을 작성하지 않았으므로 그 변경을 위해 어디에서 볼 필요가 있습니까? – dlkulp